代码之家  ›  专栏  ›  技术社区  ›  ahmet2106

Kohana3-如果errors=FALSE,则为错误模板

  •  0
  • ahmet2106  · 技术社区  · 15 年前

    在Bootstrap.php中,我已经停用了Profiler(还是激活它更好?),以及错误。

    现在如果有人正在调用一个Url,可能是:/notexist,并且没有action_notexist(),则该站点为空。

    http://twitter.com/notexistinguser ,存在“页面不存在”错误,与Kohana3相同吗?

    谢谢:)

    3 回复  |  直到 15 年前
        1
  •  2
  •   shadowhand    15 年前

    不要忽视例外,抓住它们。

        2
  •  1
  •   The Pixel Developer    15 年前

    你需要做的是抓住 Kohana_例外 引导程序.php 文件。这是我的一个项目的代码示例。

    try
    {
        echo Request::instance()
            ->execute()
            ->send_headers()
            ->response;
    }
    catch (Kohana_Exception $e)
    {
        echo Request::factory('static/404')->execute()->send_headers()->response;
    }
    

    我来解释这是怎么回事。如果请求的URL不存在路由,则它将抛出 (Kohana_例外的实例)。

    然后,我使用HMVC特性创建404页面的子请求,该页面处理模板、状态代码、日志记录和错误消息。

    将来,Kohana可能会有一个特殊的异常处理响应,但是现在您可以使用我的解决方案。

    希望这帮了你。

        3
  •  1
  •   Yan Ivanov    15 年前

    我是科哈纳新来的,但我用了以下技巧。 首先,定义一些常数,例如在生产中:

    define('IN_PRODUCTION', true);
    

    其次,创建新的异常类,例如 异常情况 继承 Kohana_例外 . 第三,替换此代码:

    echo Request::instance()
    ->execute()
    ->send_headers()
    ->response;
    

    包括以下内容:

    $request = Request::instance();
    try 
    {
        $request->execute();
    }
    catch(Exception_404 $e)
    {
        if ( ! IN_PRODUCTION)
        {
            throw $e;
        }
    
        //404 Not Found
        $request->status = 404;
        $request->response = View::factory('404');
    }
    
    print $request->send_headers()->response;
    

    推荐文章