0

到目前为止,这是我所拥有的:

应用程序/配置/core.php

Configure::write('debug', 2);

应用程序/配置/bootstrap.php

CakePlugin::loadAll(array('bootstrap' => true));

应用程序/插件/核心/bootstrap.php

Configure::write('Exception.renderer', 'Core.AppExceptionRenderer');

app/Plugin/Core/Lib/Error/AppExceptionRenderer.php

App::uses('ExceptionRenderer', 'Error');

class AppExceptionRenderer extends ExceptionRenderer {

    public function notFound($error) {
        echo $error->getMessage();
    }

    public function missingController($error) {
        echo $error->getMessage();
    }
}

那些简单的回声有效。

现在我希望每个错误函数都呈现(而不是重定向!)来自Core插件的视图,例如app/Plugin/Core/View/Pages/error.

我不想呈现静态页面(/Errors/error400.ctp例如),因为用户可以从管理面板编辑错误页面的内容。

错误页面布局应设置在名为Default.

http://book.cakephp.org/2.0/en/development/exceptions.html

4

2 回答 2

1

我想这就是您要做的,将布局和视图设置为在 beforeFilter 方法中呈现-

class AppExceptionRenderer extends ExceptionRenderer {
    public function beforeFilter() {
        $this->layout = 'YOUR_LAYOUT'; // Setting the default layout to your layout
        $this->view   = '../../Plugin/Core/View/Pages/error'; //Check this path to your ctp file
    }
...
...
}
于 2013-10-18T05:48:57.560 回答
0

您可以像这样设置自定义错误的视图

app/Plugin/Core/Lib/Error/AppExceptionRenderer.php

<?php

App::uses('ExceptionRenderer', 'Error');

class AppExceptionRenderer extends ExceptionRenderer {

    public function notFound($error) {
         $this->controller->redirect(array('controller' => 'custom_errors', 'action' => 'not_found'));
    }

    public function missingController($error) {
         $this->controller->redirect(array('controller' => 'custom_errors', 'action' => 'missing_controller'));
    }
}

应用程序/控制器/CustomErrorsController.php

<?php
App::uses('Controller', 'Controller');

class CustomErrorsController extends Controller {

    public function beforeFilter(){

    }

    public function not_found(){
        // your coding goes here.

    }

    public function missing_controller(){
        // your coding goes here.

    }
}

您可以指定操作的视图。

于 2013-10-16T11:10:25.970 回答