Cakephp - how to make error pages have its own layouts?

后端 未结 6 1404
被撕碎了的回忆
被撕碎了的回忆 2021-02-13 16:00

I wanna have a different layout for the page not found 404 page. How can i set a different layout for that page?

6条回答
  •  臣服心动
    2021-02-13 16:24

    In CakePHP 2.2.2 I changed the ExceptionRenderer in core.php with my own, like this:

    app/Config/core.php:

    Configure::write('Exception', array(
      'handler' => 'ErrorHandler::handleException',
      'renderer' => 'MyExceptionRenderer', // this is ExceptionRenderer by default
      'log' => true
    ));
    

    app/Lib/Error/MyExceptionRenderer.php:

    App::uses('ExceptionRenderer', 'Error');
    
    class MyExceptionRenderer extends ExceptionRenderer {
    
      protected function _outputMessage($template) {
        $this->controller->layout = 'error';
        parent::_outputMessage($template);
      }
    
    }
    

提交回复
热议问题