我是Zend Framework的初学者,目前遇到一个小问题:
我正在创建一个基于模块化架构的项目并请求此URL:
http://localhost/MyApp/public/ - >这是index.php所在的位置。我的核心模块在/ application / modules目录中称为“core”,如下所示:
/Applications/modules/
-- Core
---- controllers
------ ErrorController.php
------ IndexController.php
---- views
------ scripts
-------- error/error.phtml
-------- index/index.phtml.
每当我刷新页面时,我都会显示error.phtml,这很奇怪。因为我的模块确实定义了它的路由如下:
[routes]
routes.core_index_index.type = "Zend_Controller_Router_Route_Static"
routes.core_index_index.route = "/"
routes.core_index_index.defaults.module = "core"
routes.core_index_index.defaults.controller = "index"
routes.core_index_index.defaults.action = "index"
routes.core_index_index.defaults.frontend = "true"
routes.core_index_index.defaults.langKey = "route_index_page_description"
routes.core_index_index.defaults.localization.enable = "true"
另外我确实将RewriteBase设置为/ var / www / html / MyApp / public。那么为什么我的error.phtml被显示而index.phtml应该是要呈现的视图脚本?
以下是我在application.ini中的生产配置设置
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.defaultModule = core
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.params.prefixDefaultModule = "1"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
正在显示的错误页面内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zend Framework Default Application</title>
</head>
<body>
<h1>An error occurred</h1>
<h2>Page not found</h2>
</body>
</html>
真正感谢任何帮助。
答案 0 :(得分:0)
index.php是frontController。 ModRewrite应该向MyApp /发送请求到MyApp / public / index.php,这意味着您不必将整个路径放入。 我看起来你的设置中有一个错误,这就是调用ErrorController而不是IndexController的原因。 你得到什么错误?
答案 1 :(得分:0)
您的error.phtml没有显示任何堆栈跟踪。 你有两个简单的方法来展示它: - 编辑.htaccess,并更改Application_env值:
SetEnv APPLICATION_ENV development
如果您将application_env设置为“production”,则会屏蔽所有异常的堆栈跟踪。
另一种方法是编辑error.phtml文件,并删除环境周围的条件以始终显示堆栈跟踪。 (虽然不是最好的选择)
这不是答案(但是)但你会有更多的输入来解决你的问题,最明显的是请求参数。
编辑:根据尝试重新编写答案:)
答案 2 :(得分:0)
好的,我让这个工作:
由于我要求http://localhost/MyApp/public/,我必须将路由修改为:
[routes]
routes.core_index_index.type = "Zend_Controller_Router_Route_Static"
routes.core_index_index.route = "/MyApp/public/"
routes.core_index_index.defaults.module = "core"
routes.core_index_index.defaults.controller = "index"
routes.core_index_index.defaults.action = "index"
routes.core_index_index.defaults.frontend = "true"
routes.core_index_index.defaults.langKey = "route_index_page_description"
routes.core_index_index.defaults.localization.enable = "true"
变更来自:
routes.core_index_index.route = "/"
要:
routes.core_index_index.route = "/MyApp/public/"
这不是我想要的。有没有办法跳过URI的MyApp / public部分?