启动模块化 Zend Framework 项目时遇到问题

发布于 2024-12-26 07:27:10 字数 3336 浏览 2 评论 0 原文

我正在尝试建立一个带有前端和后端模块的模块化 Zend Framework 项目,但我无法让它工作。当我在网络浏览器中访问我的 public 目录时,收到以下错误消息:

致命错误:未捕获异常“Zend_Controller_Dispatcher_Exception” 消息“指定的控制器无效(错误)” /usr/share/ZendFrameworkCli/library/Zend/Controller/Dispatcher/Standard.php:248 堆栈跟踪:#0 /usr/share/ZendFrameworkCli/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), 对象(Zend_Controller_Response_Http))#1 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() #2 /usr/share/ZendFrameworkCli/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #3 /Users/Martin/Dropbox/Repositories/realestatecms/public/index.php(25): Zend_Application->run() #4 {main} 下一个异常 “Zend_Controller_Exception”,带有消息“指定的控制器无效” (错误)#0 /usr/share/ZendFrameworkCli/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), 对象(Zend_Controller_Response_Http))在 /usr/share/ZendFrameworkCli/library/Zend/Controller/Plugin/Broker.php 在第336行

我使用 Zend Framework 命令行工具创建了两个模块,这两个 module 目录具有 Bootstrap.php,其中有两个名为 Frontend_Bootstrap< 的类/code> 和 Backend_Bootstrap 分别。

我的 application.ini 文件如下所示:

[production]
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 "/frontend/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
...

我做错了什么?当我访问 http://example.com/public 时,如何让我的 Frontend_IndexController() 运行 在我的浏览器中?

编辑:如果我按照 Ivan 的回答更新配置文件,我现在会收到以下错误消息:

致命错误:未捕获的异常“Zend_Application_Resource_Exception” 带有消息“找到模块“默认”的引导程序文件,但引导程序 未找到“Default_Bootstrap”类 /usr/share/ZendFrameworkCli/library/Zend/Application/Resource/Modules.php:83 堆栈跟踪:#0 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(683): Zend_Application_Resource_Modules->init() #1 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(626): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('modules')

2 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586):

Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #3 /usr/share/ZendFrameworkCli/library/Zend/Application.php(355): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(NULL) #4 /Users/Martin/Dropbox/Repositories/realestatecms/public/index.php(25): Zend_Application->bootstrap() #5 {main} 抛出 /usr/share/ZendFrameworkCli/library/Zend/Application/Resource/Modules.php 第83行

哪里获取 Default_Bootstrap 作为类名?

I'm trying to set up a modular Zend Framework project with frontend and backend modules, but I just can't get it working. When I visit my public directory in a web browser, I get this error message:

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception'
with message 'Invalid controller specified (error)' in
/usr/share/ZendFrameworkCli/library/Zend/Controller/Dispatcher/Standard.php:248
Stack trace: #0
/usr/share/ZendFrameworkCli/library/Zend/Controller/Front.php(954):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http)) #1
/usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/Bootstrap.php(97):
Zend_Controller_Front->dispatch() #2
/usr/share/ZendFrameworkCli/library/Zend/Application.php(366):
Zend_Application_Bootstrap_Bootstrap->run() #3
/Users/Martin/Dropbox/Repositories/realestatecms/public/index.php(25):
Zend_Application->run() #4 {main} Next exception
'Zend_Controller_Exception' with message 'Invalid controller specified
(error)#0
/usr/share/ZendFrameworkCli/library/Zend/Controller/Front.php(954):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http)) in
/usr/share/ZendFrameworkCli/library/Zend/Controller/Plugin/Broker.php
on line 336

I have created the two modules using the Zend Framework command line tool, and those two module directories have Bootstrap.php with two classes in called Frontend_Bootstrap and Backend_Bootstrap respectively.

My application.ini file looks as follows:

[production]
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 "/frontend/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
...

What have I done wrong? How do I get my Frontend_IndexController() to run when I visit http://example.com/public in my browser?

EDIT: If I update my configuration file with the lines as per Ivan's answer, I now get this error message:

Fatal error: Uncaught exception 'Zend_Application_Resource_Exception'
with message 'Bootstrap file found for module "default" but bootstrap
class "Default_Bootstrap" not found' in
/usr/share/ZendFrameworkCli/library/Zend/Application/Resource/Modules.php:83
Stack trace: #0
/usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(683):
Zend_Application_Resource_Modules->init() #1
/usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(626):
Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('modules')

2 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586):

Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #3
/usr/share/ZendFrameworkCli/library/Zend/Application.php(355):
Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(NULL) #4
/Users/Martin/Dropbox/Repositories/realestatecms/public/index.php(25):
Zend_Application->bootstrap() #5 {main} thrown in
/usr/share/ZendFrameworkCli/library/Zend/Application/Resource/Modules.php
on line 83

Where is it getting Default_Bootstrap from as a class name?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最后的乘客 2025-01-02 07:27:10

我遇到了同样的问题,并在此页面上找到了解决方案:
http://updel.com/zend-framework-modular-application/

您有在 /MyApp/application/configs/application.ini 中评论以下行:

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

像这样:

;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

它解决了问题,不幸的是我不够熟练,无法解释/理解原因,抱歉。 :-)

我希望它能有所帮助。

I had the same problem and I found the solution on this page:
http://updel.com/zend-framework-modular-application/

You have to comment the following line in /MyApp/application/configs/application.ini:

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

like this:

;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

It fixed the problem, unfortunately I am not skilled enough to explain/understand why, sorry. :-)

I hope it helps though.

才能让你更想念 2025-01-02 07:27:10

你改变这一行了吗:

resources.frontController.controllerDirectory = APPLICATION_PATH "/frontend/controllers"

我认为应该是这样的:

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

然后,如果你需要索引/索引之外的其他默认模块/控制器,请使用这些配置选项:

resources.frontController.defaultControllerName = "index"
resources.frontController.defaultAction = "index"
resources.frontController.defaultModule = "frontend"

并且你不应该访问 http://yoursite.com/public。它会引发错误。公共目录应该是您的网络 DocumentRoot,您可以像这样访问它: http://yoursite.com/

did you change this line:

resources.frontController.controllerDirectory = APPLICATION_PATH "/frontend/controllers"

I think it should be like this:

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

Then if you need other default module/controller than index/index use these configuration options:

resources.frontController.defaultControllerName = "index"
resources.frontController.defaultAction = "index"
resources.frontController.defaultModule = "frontend"

And you shouldnt access http://yoursite.com/public. It will raise error. Public directory should be your web DocumentRoot and you would access it like this: http://yoursite.com/

栖竹 2025-01-02 07:27:10

Martin,当您调用 http://example.com/public Zend Framework 将抛出您看到的错误,因为路由器正在寻找名为 public< 的控制器 /em>.
查看 Zend Frame work 网站的正常方法是调用 http://example.comhttp://example.com/index.php >.
对应用程序的所有请求都通过/application/public/index.php路由。

看起来您的原始配置:

resources.frontController.controllerDirectory = APPLICATION_PATH "/frontend/controllers"

对于您的应用程序来说可能是正确的。

这些是 application.ini 中用于启用模块的典型行,

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.params.prefixDefaultModule = ""//Frontend may be your default
resources.modules = ""

根据结构的不同,您可能会有一些差异。
此外,每个模块目录包含它自己的扩展 *Zend_Application_Module_Bootstrap* 的 bootstrap.php 通常会很有帮助。

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {
    //put your code here
}

如果这不能帮助解决您的问题,请包含您的目录结构和 application.ini(您可以省略数据库设置等),如果 Index.php 已从默认值更改,则会很有帮助。
另请包含您的 Zend Framework 版本。

Martin, when you call http://example.com/public Zend Framework will throw the error you saw because the router is looking for a controller named public.
The normal way to view the a Zend Frame work web site is to call http://example.com or http://example.com/index.php.
All requests to the application are routed through /application/public/index.php.

It looks like your original configuration for:

resources.frontController.controllerDirectory = APPLICATION_PATH "/frontend/controllers"

was likely correct for your application.

These are the typical lines in the application.ini for enabling modules

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.params.prefixDefaultModule = ""//Frontend may be your default
resources.modules = ""

you may have some differences depending on structure.
Also it is usually helpful for each module directory to include it's own bootstrap.php that extends *Zend_Application_Module_Bootstrap*

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {
    //put your code here
}

If this doesn't help fix your problem please include your directory structure and your application.ini(you can leave out db settings and such), Index.php would be helpful if it has been changed from default.
Also please include your version of Zend Framework.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文