繁体   English   中英

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

[英]exception handling via controller in kohana

我正在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中,初始化代码为

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

我怎样才能解决这个问题? 谢谢。

需要检查的几件事:

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

用大写字母classes / HTTP / Exception / 404.php重命名目录

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM