I have encountered a strange problem with errors in Cake 2 which I have never had in 1.3.
When some exception raised (i.e. NotFoundException) Cake's error handling begins.. By default it instantiates CakeErrorController and does all that stuff (see the source) and.. escapes viewVars. But I have some view vars set in my AppController's beforeRender and I don't want them to be escaped, because they contain html and they are supposed to be rendered in the layout. What is the reason of such behavior? How can I tell Cake not to do that?
Thank you.
Update:
Well. I worked out 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 set:
Configure::write('Exception', array(
...,
'renderer' => 'AppExceptionRenderer',
...
));
Looks like it works as expected, but is there any more elegant solution?
Thank You.