3

我正在 Yii 框架中创建某种管理面板,并且我在登录时设置状态是这样的

public function authenticate()
{

    $record=AdminTbl::model()->findByAttributes(array('usr'=>$this->username));
    if($record===null)
        $this->errorCode=self::ERROR_USERNAME_INVALID;
    else if($record->pwd!==$this->password)
        $this->errorCode=self::ERROR_PASSWORD_INVALID;
    else
    {
        $this->_id=$record->id;
        $this->setState('roles','main');
        $this->errorCode=self::ERROR_NONE;
    }
    return !$this->errorCode;
}

我检查了状态是否真的设置,在视图中回显。后来我把这个角色放在 accessrules()

public function accessRules()
{
    return array(
        array('allow',  // allow all users to perform 'index' and 'view' actions
            'actions'=>array('index','view','create','update','admin','delete'),
            'roles'=>array('main'),
        ),
        array('deny',  // deny all users
            'users'=>array('*'),
        ),
    );
}

我无法在此用户登录的情况下访问这些页面。有什么问题?

4

2 回答 2

2

看看这里,http://www.yiiframework.com/doc/guide/1.1/en/topics.auth

您需要创建主要角色并通过用户 ID 分配它。

于 2012-07-06T16:16:53.417 回答
1

如果您需要简单的基于角色的访问控制而不需要冗长的 RBAC 流程,那么本文就是为您准备的

http://www.yiiframework.com/wiki/328/simple-rbac/

于 2014-01-23T09:54:31.470 回答