View render from AppExceptionHandler

I am working with CakePHP 2.0 and want to handle ForbiddenException. I followed the example described in the CakePHP Cookbook.

My exception is now caught in an AppExceptionHandler, but I don't know how to get from here. I want to display the corresponding view, but $this not available. Does anyone have a starting point for me?

Edit:
My code is still identical to the cookbook example:

In the application /Config/core.php

 Configure::write('Exception.handler', 'AppExceptionHandler::handle'); 

In the application /Config/bootstrap.php

 App::uses('AppExceptionHandler', 'Lib'); 

In the application /Lib/AppExecptionHandler.php

 class AppExceptionHandler { public static function handle($error) { if($error instanceOf ForbiddenException ){ echo 'Oh noes! ' . $error->getMessage(); // $this->Session->setFlash('To access the page please login'); } } } 

Regards, Bart

+4
source share
1 answer

As you mentioned in your comment, you can make copies of the error views in your own View folder and control the rendering.

If you also want to use a session, remember that in any part of your application you can use CakeSession to access the session.

http://book.cakephp.org/2.0/en/development/sessions.html#reading-writing-session-data

-2
source

Source: https://habr.com/ru/post/1388118/


All Articles