[英]Autoload models, forms inside modules in zend framework
我的應用程序結構如下:
我在student模塊的forms文件夾中有一個studentParent.php。
class Student_Form_studentParent extends Zend_Dojo_Form{
}
每當我在學生模塊的控制器中調用此表單類時,都會出現找不到類的錯誤,我將Bootstrap.php放置在學生模塊中。
class Student_Bootstrap extends Zend_Application_Module_Bootstrap
{
}
這是我的application.ini文件配置
resources.frontController.params.displayExceptions = 0
resource.modules=""
resources.view = ""
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "main_template"
我的Bootstrap.php文件:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDefaultModuleAutoloader()
{
$moduleLoader = new Zend_Application_Module_Autoloader(
array(
"namespace" => '',
"basePath" => APPLICATION_PATH.'/modules/default'
)
);
Zend_Controller_Action_HelperBroker::addPrefix('App_Action_Helper');
return $moduleLoader;
}
}
resource.modules=""
應該:
resources.modules=""
(即資源復數)。
我還建議您使用大寫字母開頭課程名稱,因此使用Student_Form_StudentParent
而不是Student_Form_studentParent
(文件名也必須為StudentParent.php
)。 我認為是個人喜好,但是如果框架以一種方式執行而您的應用程序以另一種方式執行,則您的類命名將不一致。
還有
$moduleLoader = new Zend_Application_Module_Autoloader(
array(
"namespace" => '',
"basePath" => APPLICATION_PATH.'/modules/default'
)
);
basePath應該指向包含模塊的目錄,而不是像您的示例那樣指向特定的模塊目錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.