Cakephp发生错误时重定向 [英] Cakephp redirect on error

查看:63
本文介绍了Cakephp发生错误时重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们都知道这些错误缺少控制器 CakePHP 可能引发的任何其他错误.

现在我的问题可能很简单,但是我找不到关于该主题的任何文档.

如果应该找到执行程序,我该如何重定向到未找到的 404 500执行文件页面(这意味着我如何重定向到Costum页面)?/p>

在我的config/core.php文件中,我发现了这一点:

  Configure :: write('Exception',array('handler'=>'ErrorHandler :: handleException','renderer'=>'ExceptionRenderer','log'=>真的)); 

但是我不确定我应该将其更改为什么?

解决方案

  Configure :: write('Exception',array('handler'=>'ErrorHandler :: handleException','renderer'=>'测试','log'=>真的)); 

创建文件Cake/Error/Test.php

 <?php班级考试{公共功能__construct(Exception $ exception){header('Location:/'); die();}} 

可以通过路由器防止的Missing Controller错误.创建最后一个路由器规则:

  Router :: connect('/*',array('controller'=>'app','action'=>'e404'))); 

So we all know these Error missing controller or any other error that CakePHP can throw.

Now my question may be fairly simple but i could not find any documentation on the subject.

How do i redirect to a 404 not found or a 500 execption page (meaning how do i redirect to a costum page) if an execption should be found?

in my config/core.php i found this:

    Configure::write('Exception', array(
    'handler' => 'ErrorHandler::handleException',
    'renderer' => 'ExceptionRenderer',
    'log' => true
));

However im not sure what i should change it to?

解决方案

Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'Test',
'log' => true
));

Create file Cake/Error/Test.php

<?php
class Test {
    public function __construct(Exception $exception) {
        header('Location: /');die();
    }
}

Missing Controller error you can prevent with router. Create last router rule:

Router::connect('/*', array('controller' => 'app', 'action' => 'e404'));    

这篇关于Cakephp发生错误时重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆