Custom Error Pages for CakePHP Plugin
I'm working with CakePHP 1.3 and I'm looking to have any errors (missing controller, missing page, etc) that contain an /admin/ prefix to come from one of my plugins (using a plugin layout) as opposed to being served using my web sites default.c开发者_如何学Pythontp layout.
Where is the best place to put the code for this?
I was able to solve this by overloading the the _outputMessage() function within ErrorHandler by saving the following as app/app_error.php
<?php
class AppError extends ErrorHandler {
function _outputMessage( $template ) {
$url = $this->controller->params['url']['url'];
if( substr( $url, 0, 6 ) == 'admin/' ) {
$this->controller->layout = 'admin_default';
}
parent::_outputMessage( $template );
}
}
?>
精彩评论