我正在制作我的第一个zend应用程序,但是我遇到了自动加载模块的问题。 这时我加载了一个我保存在“用户”形式的“表单”中的表单,但是我收到了“致命错误”。 这是我的配置:
的application.ini:
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resouces.modules = ""
resources.frontController.params.displayExceptions = 1
;my library dir
autoLoaderNameSpaces.test = "Test_"
resources.view.helperPath.Zend_View_Helper = APPLICATION_PATH "/modules/default/views/helpers"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = layout
resources.view.doctype = "HTML5"
目录树:
application
-configs
-layouts
-modules
--default
--users
---controllers
----indexController.php -> class Users_IndexController extends Zend_Controller_Action
---forms
----Login.php -> class Users_Form_Login extends Zend_Form
---models
---views
---Bootstrap.php -> class Users_Bootstrap extends Zend_Application_Module_Bootstrap{}
--Bootstrap.php -> class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{}
。 。
在Users_IndexController的indexAction()中我写道:
$form = new Users_Form_Login();
我收到了这个错误:
Fatal error: Class 'Users_Form_Login' not found in [...]/application/modules/users/controllers/IndexController.php on line 39
修改
@Tim Fountain补充的课程内容:
Bootstrap文件:
在Bootstrap.php中:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initActionHelpers ()
{
$config = $this->getOptions();
$acl = new Test_Acl($config['acl']);
$aclHelper = new Test_Controller_Action_Helper_Acl(null, array('acl'=>$acl));
Zend_Controller_Action_HelperBroker::addHelper($aclHelper);
}
}
在/Users/Bootstrap.php中:
class Users_Bootstrap extends Zend_Application_Module_Bootstrap
{
}
答案 0 :(得分:2)
每个模块都有一个bootstrap文件。在users / Bootstrap.php文件中,您是否已为模块命名空间?
/**
* Sets up the autoloading for this module. This function must be first in the bootstrap else other bootstrap functions might not work.
*/
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Users_',
'basePath' => APPLICATION_PATH . "/modules/users",
));
return $autoloader;
}
答案 1 :(得分:1)
您的模块引导未运行,因为您的配置文件中有拼写错误:
resouces.modules = ""
应该是
resources.modules = ""
然后它应该工作。
编辑:在这种情况下,第一步是查看是否正在运行bootstraps。编辑您的modules/users/Bootstrap.php
课程并暂时添加如下方法:
protected function _initTest()
{
echo "User bootstrap run";
exit;
}
在浏览器中重新加载页面,如果正在运行bootstraps,您应该会看到该消息。之后再删除它。如果是,则仔细检查表单类的文件名和名称(区分大小写)。