cakephp - 在 404 Not Found 错误上终止会话

cakephp - killed session on 404 Not Found error

我使用 cakephp-2.5.4,当我遇到 404 错误时,用户会话终止并且用户从应用程序注销。

有人可以帮忙吗?

public $components = array (
    'Session'
);

解决这个问题:

请试试这个

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

如果有任何问题,请告诉我。

解法:

  1. core.php

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

  2. bootstrap.php

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

  3. 在 Lib 文件夹中添加 AppErrorHandler class,函数如下

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