PHP/Zend:致命错误 - 未找到类
我有一个具有以下目录结构的 Zend 项目:
/myApp
/application
Bootstrap.php
/configs
application.ini
/layouts
/modules
/default
/controllers
MessageController.php
ErrorController.php
IndexController.php
/models
/DbTable
Message.php
Message.php
MessageMapper.php
/views
Bootstrap.php
/login
/controllers
/forms
/library/login
/models
/plugins
/views
Bootstrap.php
/data/db
/library/zend
/public
http://localhost/ - 工作正常,但我无法获取登录模块以及默认模块内的消息起作用。我收到以下错误:
致命错误:第 14 行 /Library/WebServer/Documents/myApp/application/modules/default/controllers/MessageController.php 中找不到类“Application_Module_Default_Model_MessageMapper”
我确信我没有初始化我需要的东西。这是我的代码的样子..
application.ini
autoloaderNamespaces[] ="Message_"
autoloaderNamespaces[] ="Login_"
autoloadernamespaces.0 = "Zend_"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.defaultControllerName = "index"
resources.frontController.defaultActionName = "index"
resources.frontController.params.displayExceptions = 0
resources.frontController.defaultModule = "default"
resources.frontController.params.prefixDefaultModule = "1"
resources.frontController.plugins[] = "Login_Plugin_SecurityCheck"
resources.modules = ""
/application/bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('HTML5');
}
}
/public/index.php
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
require_once 'Zend/Application.php';
require_once('Zend/Loader/Autoloader.php');
$autoloader = Zend_Loader_Autoloader::getInstance();
/module/default/controllers/MessageController.php
$message = new Application_Module_Default_Model_MessageMapper();
$this->view->entries = $message->fetchAll();
让我知道更多详细信息是否有帮助。任何帮助将不胜感激。
I have a Zend project with the following directory structure:
/myApp
/application
Bootstrap.php
/configs
application.ini
/layouts
/modules
/default
/controllers
MessageController.php
ErrorController.php
IndexController.php
/models
/DbTable
Message.php
Message.php
MessageMapper.php
/views
Bootstrap.php
/login
/controllers
/forms
/library/login
/models
/plugins
/views
Bootstrap.php
/data/db
/library/zend
/public
http://localhost/ - works fine but i can not get the login module and the message inside the Default module to work. I get the following error:
Fatal error: Class 'Application_Module_Default_Model_MessageMapper' not found in /Library/WebServer/Documents/myApp/application/modules/default/controllers/MessageController.php on line 14
I am sure i am not initialising something i need to. Here is what my code looks like..
application.ini
autoloaderNamespaces[] ="Message_"
autoloaderNamespaces[] ="Login_"
autoloadernamespaces.0 = "Zend_"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.defaultControllerName = "index"
resources.frontController.defaultActionName = "index"
resources.frontController.params.displayExceptions = 0
resources.frontController.defaultModule = "default"
resources.frontController.params.prefixDefaultModule = "1"
resources.frontController.plugins[] = "Login_Plugin_SecurityCheck"
resources.modules = ""
/application/bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('HTML5');
}
}
/public/index.php
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
require_once 'Zend/Application.php';
require_once('Zend/Loader/Autoloader.php');
$autoloader = Zend_Loader_Autoloader::getInstance();
/module/default/controllers/MessageController.php
$message = new Application_Module_Default_Model_MessageMapper();
$this->view->entries = $message->fetchAll();
Let me know if any more details would help. Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过:
另外,您是否在模块 Bootstrap.php 文件中自动加载模块?我不确定自从我使用 ZF 以来它发生了多少变化,但我必须包括这一点:
Have you tried:
Also, are you autoloading your module in the module Bootstrap.php file? I'm not sure how much it has changed since I used ZF, but I had to include this:
我也有同样的问题,但我的原因很简单,
我有一个表单 Form_Template_Add &控制器TemplateController。
我从控制器调用了表单 - new Form_Template_Add();
我的表单驻留在文件夹模板中。
问题在于文件夹名称,请参阅模板中的“t”是小写字母,而控制器和控制器的“T”是大写字母。类名是 caps。
我将文件夹名称更改为 Template &它起作用了......胡亚
me too had the same issue, but my cause was very simple
i had a form Form_Template_Add & a controller TemplateController.
From the controller i called the form - new Form_Template_Add();
My form resides in a folder template.
Issue was with the folder name, see the 't' in template is small caps, while 'T' for controller & class name is caps.
I changes folder name to Template & it worked... hooya
确保您在每个模块目录中创建了一个 Bootstrap.php,如下所示:
其中 Admin 是模块的名称。另外,确保目录 module/admin/forms 中实际上有一个文件 Login.php ,其类为 Admin_Form_Login
[Zend_Form][1.11.1] 错误消息 致命错误:类在 ...\modules\default\controllers\IndexController.php 中找不到“Admin_Form_Login”
Make sure you have created a Bootstrap.php in each module directory, which looks like:
In which Admin is the name of the module. Also, make sure there is actually a file Login.php inside directory modules/admin/forms with a class Admin_Form_Login
[Zend_Form][1.11.1] Error Message Fatal error: Class 'Admin_Form_Login' not found in ...\modules\default\controllers\IndexController.php