0
votes

I have encountered a quite complex situation to render error page 1) the cake exception NotFoundException is thrown from a plugin; 2) I want to render a layout from app instead of from this plugin;

I have tried to set $this->layout='default'; in the plugin controller beforeFilter method, but still the plugin layout instead of the app layout is rendered.

I looked into the CakeErrorController but did not find where the layout is set.

any idea how to manage this?

1
I had a similar issue: cakephp.lighthouseapp.com/projects/42648/tickets/… - seems like there is no easy solution to this. I hate extending the exceptions just for switching the layout :) - mark

1 Answers

1
votes

I am not certain if this will work for you, but this is what I did. I (in my AppController) set it in the __construct() function:

    function __construct() {

        parent::__construct();

        if ($this->name == 'CakeError') { 
            $this->layout = 'default';
            $this->constructClasses();


            $this->beforeFilter();

            $this->beforeRender();
        }   
    }

Again, your method may vary, but that is my implementation of it.

Also, you can set it using the AppError.php file in the defined error handler. Be warned, my approach was for Cake 1.3, so I am not sure how different the AppError file is in Cake2.

<?php
class AppError extends ErrorHandler {


function error403($params) {
    extract($params, EXTR_OVERWRITE);

    if (!isset($url)) {
        $url = $this->controller->here;
    }

    $this->controller->helpers = array_merge( $this->controller->helpers, array( 'Asset.Asset', 'Auth' ) );

    $url = Router::normalize($url);


    $this->controller->set(array(
        'code' => '403',
        'name' => __('Permission Denied', true),
        'message' => $message,
        'base' => $this->controller->base
    ));


    $this->_outputMessage('error403');

    }   
}