CakePHP ACL中拒绝的内存耗尽

时间:2013-03-12 21:20:57

标签: cakephp cakephp-2.0 acl

运行CakePHP 2.2并拥有一个在控制器上具有拒绝的组,然后在其他几个控制器上允许。如果我以该组的用户身份登录并尝试访问控制器,我没有明确的权限,那么我收到以下错误:

  

致命错误:允许的内存大小为134217728字节耗尽(尝试过   分配32个字节)   第672行的/var/www/project/lib/Cake/Network/CakeResponse.php

还有:

  

致命错误:允许的内存大小为134217728字节耗尽(尝试过   分配80个字节)   第155行的/var/www/project/lib/Cake/Event/CakeEventManager.php

仅当用户无权访问控制器时才会发生这种情况。有没有想过为什么会这样? AppController配置为:

public $components = array(
    'Acl',
    'Auth' => array(
        'authorize' => array(
            'Actions' => array('actionPath' => 'controllers'),
        ),
        'Form' => array(
            'userModel' => 'User',
            'fields' => array(
                'username' => 'username',
                'password' => 'password'
            )
        ),
        'loginAction' => array(
            'controller' => 'users',
            'action' => 'login',
        ),
        'loginRedirect' => '/users/dashboard', //'/admin/customers/index',//'/admin/tread_designs', // '/shopfloor/build/app.html',
        'logoutRedirect' => '/users/login', //'/shopfloor/build/app.html'
    )
);

andFilter:

public function beforeFilter() {
    parent::beforeFilter();

    if($this->RequestHandler->responseType() == 'json'){
        $this->RequestHandler->setContent('json', 'application/json' );
    }

    $this->Auth->ajaxLogin = '/users/session_expired';
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
}

对此感到困惑,感谢您的帮助。此外,如果我的内存限制高达1024MB,它只会超时。愚蠢起来了。

更新 当我尾随-f mysql查询日志时,我可以看到生成此错误的请求一遍又一遍地尝试相同的3个查询。

1 个答案:

答案 0 :(得分:0)

解决。需要设置'unauthorizedRedirect'=> AppController中的false

示例:

    public $components = array(
    'Acl',
    'Auth' => array(
        'authorize' => array(
            'Actions' => array('actionPath' => 'controllers'),
        ),
        'Form' => array(
            'userModel' => 'User',
            'fields' => array(
                'username' => 'username',
                'password' => 'password'
            )
        ),
        'loginAction' => array(
            'controller' => 'users',
            'action' => 'login',
        ),
        'loginRedirect' => '/users/dashboard', 
        'logoutRedirect' => '/users/login', 
        'unauthorizedRedirect' => false 
    ));