正在显示 error.phtml(找不到页面错误)

发布于 2024-10-08 03:10:29 字数 2077 浏览 1 评论 0原文

我是使用 Zend Framework 的初学者,目前遇到一个小问题:

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

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

非常感谢任何帮助。

I am a beginner working with Zend Framework, and currently having a small problem:

I am creating a project based on modular architecture and requesting this URL:

http://localhost/MyApp/public/ --> which is where index.php resides. My core module is called "core" inside /application/modules directory as follows:

/Applications/modules/
-- Core
---- controllers
------ ErrorController.php
------ IndexController.php
---- views
------ scripts
-------- error/error.phtml
-------- index/index.phtml.

Everytime i refresh the page i get error.phtml displayed which is weird. Because my module does define it's routes as follows:

[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"

Plus the fact that i do have RewriteBase set to /var/www/html/MyApp/public. So why is my error.phtml being displayed while index.phtml should be the view script to be rendered?

Following is my setup for production config in 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"

Content of error page being displayed:

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

Any help is truly appreciated.

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

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

发布评论

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

评论(3

秋叶绚丽 2024-10-15 03:10:29

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

index.php is the frontController.
ModRewrite should send requests to MyApp/ to MyApp/public/index.php, meaning you shouldn't have to put the whole path in.
I looks like there's an error in your setup which is why the ErrorController is being called rather than IndexController.
What error do you get?

梦在深巷 2024-10-15 03:10:29

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

SetEnv APPLICATION_ENV development

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

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

这还不是答案,但您将为您的问题提供更多输入,最显着的是请求参数。

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

Your error.phtml doesn't show any stack trace.
You got 2 simple ways to show it :
- edit your .htaccess, and change the Application_env value :

SetEnv APPLICATION_ENV development

If you application_env is set to "production", all the exception's stack trace is masked.

The other way is to edit the error.phtml file, and remove the condition around the environment to always disply the stack trace. (not the best option though)

This is not the answer (yet) but you'll have much more input for your problems, most notably the request parameters.

edit : rewrote answer based on tries :)

指尖上的星空 2024-10-15 03:10:29

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

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

Okay, i got this to work:

Since am requesting http://localhost/MyApp/public/, i had to modify the routing to:

[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"

Change was from:

routes.core_index_index.route = "/"

To:

routes.core_index_index.route = "/MyApp/public/"

Which is not exactly what i was looking for. Is there a way to skip /MyApp/public part of the URI?

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