I had a strange problem with errors in Cake 2 that I never had in version 1.3.
When a certain exception occurs (i.e. NotFoundException), Cake error processing begins. By default, it launches CakeErrorController and does all this (see source ) and .. escapes viewVars. But I have some points of view set in my AppController beforeRender, and I do not want them to be escaped because they contain html and they should be displayed in the layout. What is the reason for this behavior? How can I tell Cake not to do this?
Thanks.
Update:
Well. I developed some solution:
I created Controller / AppErrorController.php :
App::uses('CakeErrorController', 'Controller'); class AppErrorController extends CakeErrorController { public function beforeRender() { AppController::beforeRender(); } }
and Lib / Error / AppExceptionRenderer.php :
App::uses('ExceptionRenderer', 'Error'); class AppExceptionRenderer extends ExceptionRenderer { protected function _getController($exception) { App::uses('AppErrorController', 'Controller'); if (!$request = Router::getRequest(false)) { $request = new CakeRequest(); } $response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); try { $controller = new AppErrorController($request, $response); } catch (Exception $e) { $controller = new Controller($request, $response); $controller->viewPath = 'Errors'; } return $controller; } }
And in Config / core.php I installed:
Configure::write('Exception', array( ..., 'renderer' => 'AppExceptionRenderer', ... ));
It seems to work as expected, but is there an even more elegant solution?
Thanks.
source share