【问题标题】:Kohana 404 custom pageKohana 404 自定义页面
【发布时间】:2012-06-12 09:53:12
【问题描述】:

我一直在环顾四周并关注每个教程,其中有一个很突出。 http://blog.lysender.com/2011/02/kohana-3-1-migration-custom-error-pages/

  1. 正在检测错误
  2. 正在处理异常

但是我似乎找不到一个例外。我目前有这个异常

Fatal error: Exception thrown without a stack frame in Unknown on line 0

我的所有代码都与站点链接相同。请帮助我.. 我一直在为此烦恼,我也浏览过这里Kohana 3 - redirect to 404 page,但由于我是初学者,真的很难理解它。我还发现从 KO 3.0 到 3.1 进行了重大改造,那么 KO 3.2 怎么样?谢谢你们的帮助:)

【问题讨论】:

标签: php exception-handling kohana kohana-3.2


【解决方案1】:

来自 kohana 源代码。

- > If you receive *Fatal error: Exception thrown without a stack frame in Unknown on line 0*, it means there was an error within your exception handler. If using the example above, be sure *404.php* exists under */application/views/error/*.

也许有帮助。这可能已经修复,但我并没有那么多关注 kohana 的发展。它与拉取请求 #246:https://github.com/kohana/core/pull/246 相关,这是来源:https://github.com/kohana/core/pull/246/files#L208L76

【讨论】:

    【解决方案2】:

    这是我使用 Kohana 3.2 的方法

    • index.php 中添加异常处理内容
    尝试 { $request = $request->execute(); } 捕捉(Kohana_HTTP_Exception_404 $e) { $request = Request::factory('errors/404')->execute(); } 捕获(异常 $e) { $request = Request::factory('errors/500')->execute(); } echo $request->send_headers()->body();
    • 然后写入错误控制器
    类 Controller_Errors 扩展控制器 { 公共函数 __construct($request, $response) { 父::__construct($request, $response); } 公共函数 action_404() { $this->response->body(View::factory('errors/404')); } 公共函数 action_500() { $this->response->body(View::factory('errors/500')); } }
    • 创建2个对应的错误页面(views/errors中的404.php和500.php)

    • 将新路由添加到 bootstrap.php 或使用默认路由(取决于您的项目结构),只需确保在抛出异常时可以到达 Controller_Errors

    • 现在每次在控制器中抛出异常时,它都会显示自定义错误页面,如下所示
    抛出新的 HTTP_Exception_404;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 2010-11-04
      • 2012-10-26
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多