2012-06-12 56 views
0

我一直在环顾四周,关注每个教程,其中有一个突出。 http://blog.lysender.com/2011/02/kohana-3-1-migration-custom-error-pages/ < - 我也跟着本教程和一切顺利Kohana 404自定义页面

  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怎么样?感谢您的帮助:)

+0

请阅读有关该错误信息的手册:http://php.net/manual/en/function.set-exception-handler.php - 谢谢你! – hakre

回答

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

1

这里是我做它的Kohana 3.2

  • 添加例外的index.php
处理的东西
 
    try 
    { 
     $request = $request->execute(); 
    } 
    catch(Kohana_HTTP_Exception_404 $e) 
    { 
     $request = Request::factory('errors/404')->execute(); 
    } 
    catch(Exception $e) 
    { 
     $request = Request::factory('errors/500')->execute(); 
    } 

    echo $request->send_headers()->body(); 
  • 然后写入错误控制器
 
class Controller_Errors extends Controller 
{ 
    public function __construct($request, $response) 
    { 
     parent::__construct($request, $response); 
    } 

    public function action_404() 
    { 
     $this->response->body(View::factory('errors/404')); 
    } 

    public function action_500() 
    { 
     $this->response->body(View::factory('errors/500')); 
    } 
} 
  • 创建2个相应的错误页面(404.php和500.php的意见/错误)

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

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