【问题标题】:error.phtml is being displayed (Page not found error)error.phtml 正在显示(页面未找到错误)
【发布时间】:2010-12-16 14:59:14
【问题描述】:

我是 Zend 框架的初学者,目前遇到一个小问题:

我正在创建一个基于模块化架构的项目并请求此 URL:

http://localhost/MyApp/public/ --> index.php 所在的位置。我的核心模块在 /application/modules 目录中被称为“核心”,如下所示:

/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>

非常感谢任何帮助。

【问题讨论】:

  • 是否抛出异常?错误的内容是什么?
  • 请在我的帖子中查看修改

标签: php model-view-controller zend-framework


【解决方案1】:

index.php 是前端控制器。 ModRewrite 应该向 MyApp/ 发送请求到 MyApp/public/index.php,这意味着您不必将整个路径放入。 我看起来您的设置中有错误,这就是调用 ErrorController 而不是 IndexController 的原因。 你得到什么错误?

【讨论】:

  • 是的 (PHP+Apache) 正在工作。运行 zend 应用程序的请求循环已完成......但我现在所知道的是,ErrorController 被调用,并且它的视图脚本 error.phtml 被渲染,而不是到达 IndexController。
  • 我猜你的观点有问题。虽然很抱歉,但我不会提供更多帮助......
【解决方案2】:

您的 error.phtml 没有显示任何堆栈跟踪。 你有两种简单的方法来展示它: - 编辑您的 .htaccess,并更改 Application_env 值:

SetEnv APPLICATION_ENV development

如果您将 application_env 设置为“生产”,则会屏蔽所有异常的堆栈跟踪。

另一种方法是编辑 error.phtml 文件,并删除环境周围的条件以始终显示堆栈跟踪。 (虽然不是最好的选择)

这还不是答案(目前),但您会为您的问题提供更多输入,尤其是请求参数。

编辑:根据尝试重写答案:)

【讨论】:

  • 是的,对不起,我有,但我的图表并不正确。问题依然存在
【解决方案3】:

好的,我得到了这个工作:

由于我请求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 部分?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2014-03-15
    相关资源
    最近更新 更多