通过kohana中的控制器进行异常处理

时间:2013-06-20 11:12:06

标签: php kohana kohana-3.3

我正在http://kohanaframework.org/3.3/guide/kohana/tutorials/error-pages关注 Kohana 3.3

的教程

以下代码位于 classes / http / exception / 404.php

 <?php
    class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
        public function get_response(){
            $view = View::factory('errors/404');
            $view->message = $this->getMessage();
     
            $response = Response::factory()
                ->status(404)
                ->body($view->render());
     
            return $response;
        }
    }

尝试提供错误的网址时

本地主机/ MyApp的/ XYZ

出现以下错误

ErrorException [ Parse Error ]:
APPPATH\classes\http\exception\404.php [ 3 ]
1 <?php
2 class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
3 
4 
5 
6 
7 
8 
{PHP internal call} » Kohana_Core::shutdown_handler()

bootstrap.php 中,init的代码是

Kohana::init(array(
    'base_url'   => '/myapp/',
    'errors' => TRUE,
    'index_file' => FALSE,
));

我该如何解决这个问题?谢谢。

2 个答案:

答案 0 :(得分:1)

要检查的几件事情:

  • errors/404
  • 是否存在APPPATH/views/errors/404.php视图?
  • 类文件路径和名称是否使用StudlyCaps APPPATH\Classes\HTTP\Exception\404.php

答案 1 :(得分:0)

使用大写字母重命名目录 的类/ HTTP /异常/ 404.php