无法访问模块控制器中的模块表单
我有一个测试模块。在测试模块中,我在窗体文件夹中有一个窗体。无法访问模块控制器中的模块表单
myproject的/应用/模块/测试/形式/ TestForm.php
class Test_Form_TestForm extends Zend_Form {
//form elements
}
myproject的/应用/模块/测试/控制器/ TestController.php
class Test_TestController extends Zend_Controller_Action {
public function indexAction() {
$this->view->form = new Test_Form_TestForm(); // this is generating error
}
} // end class
表格初始化在控制器中产生以下错误:
Fatal error: Class 'Test_Form_TestForm' not found in C:\wamp\www\student\application\modules\notification\controllers\NotificationController.php on line 16
如何使此表单在控制器中可访问。同一类型的案件正在使用默认控制器。我知道我必须使用Form_指示器在引导程序中注册模块,但不知道确切的语法。
您还可以初始化多个模块在一个单独的函数在一个引导文件,如:
protected function _initAutoloaders() {
$test_loader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Test',
'basePath' => APPLICATION_PATH . '/modules/test'
));
$mynew_loader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Mynew',
'basePath' => APPLICATION_PATH . '/modules/mynew'
));
}
为了使Zend Autoloader
适用于您的模块,您需要为所有模块启动引导程序,并且还需要对模块资源进行初始化。
所以,在你application/modules/test/Bootstrap.php
:
class Test_Bootstrap extends Zend_Application_Module_Bootstrap {}
UPD:
而在你application/configs/application.ini
:有关模块中自动加载
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
更多信息here
我已经在** application/modules/test/Bootstrap.php中创建了Test_Bootstrap类,但同样的错误。你能提供一些更多的信息。 – Awan 2011-02-06 08:55:04
我不知道这是不是最好的方法,但它的工作原理。
在你的引导
...
$autoloader = new Zend_Loader_Autoloader_Resource(array('namespace' => '', 'basePath' => APPLICATION_PATH));
$autoloader->addResourceType('Test_Form', '/test/forms', 'Test_Form');
...
维卡的回答是模块如何设置自动加载正确的。
您的错误指出无法在NotificationController控制器的通知模块中找到表单类。
所以你需要有引导类的通知模块
在你application/modules/notification/Bootstrap.php:
class Notification_Bootstrap extends Zend_Application_Module_Bootstrap {}
Vika的回答似乎是正确的。
如果您仍然有问题,尝试修改的application.ini
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleDefault = "test"
resources.modules[] = "test"
resources.modules[] = "other"
如果指定的资源清单准确模块名称,Zend公司将自动奇迹般地登记表和其他资源的自动装载机。在调试案例modules/test/Boostrap。php应该被触发并且里面有_init方法。玩的开心。
主Bootstrap中的最短路径... – Awan 2011-02-08 18:24:18