1

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'
);

2 Answers2

2

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) {
        }
    }
    
0

To solve this issue:

Please do try this

public $helpers = array('Session', 'Html', 'Form');
public $uses = array('Users','Persons');

    public $components = array('Auth' => array(
            'authenticate' => array(
                'Form' => array(
                            'fields' => array('username' => 'email_address'),
                            'passwordHasher' => array('className' => 'Md5', 'hashType' => 'md5'),
                        )
            ),
            'loginAction' => array(
                'controller' => 'user_masters',
                'action' => 'login',
                'admin' => true,
            ),
            'loginRedirect' => array(
                'controller' => 'user_masters',
                'action' => 'dashboard',
                'admin' => true,
            ), 'logoutRedirect' => array(
                'controller' => 'user_masters',
                'action' => 'login',
                'admin' => true,
            )), "Cookie", "Session", "Email", 'RequestHandler', 'Security');

Let me know if any issue.

Faisal
  • 4,591
  • 3
  • 40
  • 49