Give all of your error messages a different layout

By default CakePHP will use the default.ctp layout to display any error messages.

In some cases this may not be desirable as your default.ctp might contain navigational and design elements, CSS and JS files, which really take away from the way the error message is displayed.

Usually an error message should be displayed in a clean and simple layout that only focuses on the error itself.

Thankfully, the remedy for this is pretty simple…

First, create a new layout and call it error.ctp (place in the app/views/layouts, of course).

Then add this to your App Controller:

function beforeRender () {
       $this->_setErrorLayout();
}

function _setErrorLayout() {
    if($this->name == 'CakeError') {
        $this->layout = 'error';
    }
}

That’s all folks.

P.S. Note, this is different than modifying error message views. For instructions on that, please look at the helpful instructions in the actual error message.

%d bloggers like this: