简体   繁体   English

Zend无法找到表格

[英]Zend Unable to locate form

I have a small (very small) zend project that covers two modules, the admin and the front module. 我有一个很小的(非常小的)zend项目,其中包含两个模块,即admin和front模块。 I have also managed to create a form under the 'front' module and was also able to use it in the controllers of the front module as well. 我还设法在“ front”模块下创建了一个表单,并且还能够在front模块的控制器中使用它。 Now, my problem is that when I created a form under the 'admin' module, and use it in the admin controllers as well, the php cannot anymore detect where to locate the class. 现在,我的问题是,当我在“ admin”模块下创建表单,并在管理控制器中也使用它时,php无法再检测到该类的位置。 Thus, this error is displayed: 因此,显示此错误:

Fatal error: Class 'Admin_Form_Login' not found in C:\xampp\htdocs\projects\zend\finder\application\modules\admin\controllers\IndexController.php on line 18

I was so confused that in the front module, it is working but on the admin module, very similar way of creation and usage, it fails. 我很困惑,以至于在前端模块中它可以正常工作,但是在管理模块上(非常相似的创建和使用方式),它失败了。 NOTE: I used zf tool to create the forms. 注意:我使用zf工具创建表单。

Here is my application.ini, maybe this might help. 这是我的application.ini,也许这可能有所帮助。

phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

resources.modules[] =

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

resources.view.helperPath.Finder_View_Helper = APPLICATION_PATH "/../library/Finder/View/Helper"

I am using Zend 1.11.12 for this. 我为此使用Zend 1.11.12。

Thanks in advance. 提前致谢。

If you are adding a form to a Library then you want it in library/admin/form/login.php (alter the case of the path accordingly) - not in the module '/modules/Admin/Controllers etc' folder. 如果要将表单添加到库中,则需要在library / admin / form / login.php中(相应地更改路径)-而不是在模块“ / modules / Admin / Controllers”文件夹中。 I am not sure if this is a relevant point but i made it anyway... 我不确定这是否相关,但无论如何我还是做到了……

Then you make sure you load your module using the autoLoadNamespaces in your application.ini and the Admin folder should be in your library folder. 然后,确保使用application.ini中的autoLoadNamespaces加载模块,并且Admin文件夹应位于库文件夹中。

I'm guessing you don't have a module bootstrap class, as everything else looks fine. 我猜你没有模块引导程序类,因为其他一切看起来都很好。 So all you need to do is create a file at application/modules/admin/Bootstrap.php which contains the following: 因此,您所需要做的就是在application/modules/admin/Bootstrap.php创建一个文件,其中包含以下内容:

<?php

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{

}

this will be run by your application bootstrap, and Zend_Application_Module_Bootstrap by default sets up an instance of the module resource autoloader, which will in turn enable resources classes beginning with Admin_ . 这将由您的应用程序引导程序运行,并且Zend_Application_Module_Bootstrap默认情况下会设置模块资源自动加载器的实例,该实例又将启用以Admin_开头的资源类。

Did you declare the namespace for those forms ? 您是否声明了这些表单的名称空间? In my module's Bootstrap.php (/application/modules/admin/Bootstrap.php), I use the following code: 在模块的Bootstrap.php(/application/modules/admin/Bootstrap.php)中,我使用以下代码:

    //Loads the autoloader resources

    $moduleName = 'admin';
    $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
            'basePath' => APPLICATION_PATH ."/modules/".$moduleName."/",
            'namespace' => '',
            'resourceTypes' => array(
                    //Tells the application where to find the forms
                    'form' => array(
                            'path' => 'forms/',
                            'namespace' => ucfirst($moduleName).'_Form_'
                    ),
                    //Tells the application where to find the models
                    'model' => array(
                            'path' => 'models/',
                            'namespace' => ucfirst($moduleName).'_Model_'
                    )
            ),
    ));

from what i see you didn't add the Admin namespace to the autoloader. 从我看到的结果来看,您没有将Admin名称空间添加到自动加载器中。 If you are using the Autloader and the Form is under include_dir/Admin/Form/Login.php, try 如果您使用的是Autloader,并且表单位于include_dir / Admin / Form / Login.php下,请尝试

autoloaderNamespaces[] = "Admin_"

in your config. 在您的配置中。

More Info about the Autoloader 有关自动装带器的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM