Search code examples
cakephpcakephp-2.5

cakephp - killed session on 404 Not Found error


i use cakephp-2.5.4 and when i encounter a 404 error, user session killed & user logout from application.

can someone help?

public $components = array (
    'Session'
);

Solution

  • Solution:

    1. core.php

      Configure::write('Exception.handler','AppErrorHandler::handleException');

    2. bootstrap.php

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

    3. add AppErrorHandler class in Lib folder with following function

      public static function handleException(Exception $exception)
      {
          if($exception instanceof MissingControllerException ){
              return false;
          }
          $config = Configure::read('Exception');
          //self::_log($exception, $config);
          $renderer = isset($config['renderer']) ? $config['renderer'] : 'ExceptionRenderer';
          if ($renderer !== 'ExceptionRenderer') {
              list($plugin, $renderer) = pluginSplit($renderer, true);
              App::uses($renderer, $plugin . 'Error');
          }
          try {
              $error = new $renderer($exception);
              $error->render();
          } catch (Exception $e) {
          }
      }