Yii checkAccess方法在登录请求中返回false

时间:2014-09-03 15:37:12

标签: php authentication yii

我编写了以下代码,以便在身份验证方法

中为用户分配角色
$auth=Yii::app()->authManager;

if(!$auth->isAssigned($user->type,$user->id))
{
    if($auth->assign($user->type,$user->id))
    {
            Yii::app()->authManager->save();    
            var_dump(Yii::app()->authManager->getRoles($user->id));
            var_dump(Yii::app()->user->checkAccess($user->type));
    }
}

上面的代码返回

array(1) { 'USER' => class CAuthItem#77 (8) { private $_auth => class CPhpAuthManager#76 (10) { public $authFile => string(25) "protected/config/auth.php" private $_items => array(6) { ... } private $_children => array(2) { ... } private $_assignments => array(2) { ... } public $showErrors => bool(false) public $defaultRoles => array(0) { ... } public $behaviors => array(0) { ... } private $_initialized => bool(true) private $_e => NULL private $_m => NULL } private $_type => int(2) private $_name => string(4) "USER" private $_description => string(14) "User Role Type" private $_bizRule => string(0) "" private $_data => string(0) "" private $_e => NULL private $_m => NULL } }

bool(false)

但是如果我在下一个请求中使用checkAccess,它将返回true.something,如save方法异步工作,并且不会在调用时保存规则。

这是我对auth的配置:

            'authManager'=>array(
                'class'     =>  'CPhpAuthManager',
                'authFile'  =>  'protected/config/auth.php',
            ),

我关注this wiki

1 个答案:

答案 0 :(得分:0)

尝试不缓存

Yii::app()->user->checkAccess($user->type, array(), false);