Yii Rights ::错误403您未被授权执行此操作

时间:2013-12-01 08:09:40

标签: yii yii-extensions yii-components

我是yii的新手。我根据文档在protected / modules / rights中安装了yii-rights。但不能正常使用。有些东西缺失,我无法找到。 localhost / index.php /右页运行良好。但是当我按下“权限”,“角色”,“任务”,“操作”时。它显示

“错误403 您无权执行此操作。“

这是我的主要配置::

'import'=>array(
 'application.modules.right.*',
 'application.modules.right.models*',
 'application.modules.rights.components.*',
 ),
'rights'=>array(

 'superuserName'=>'Admin', // Name of the role with super user privileges.
 'authenticatedName'=>'Authenticated', // Name of the authenticated user role.
 'userIdColumn'=>'id', // Name of the user id column in the database.
 'userNameColumn'=>'username', // Name of the user name column in the database.
 'enableBizRule'=>true, // Whether to enable authorization item business rules.
 'enableBizRuleData'=>false, // Whether to enable data for business rules.
 'displayDescription'=>true, // Whether to use item description instead of name.
 'flashSuccessKey'=>'RightsSuccess', // Key to use for setting success flash messages.
 'flashErrorKey'=>'RightsError', // Key to use for setting error flash messages.

 'baseUrl'=>'/rights', // Base URL for Rights. Change if module is nested.
  'layout'=>'rights.views.layouts.main', // Layout to use for displaying Rights.
  'appLayout'=>'application.views.layouts.main', // Application layout.
  'cssFile'=>'rights.css', // Style sheet file to use for Rights.
 'install'=>false, // Whether to enable installer.
'debug'=>false,
),
'components'=>array(
  'user'=>array(
  'class'=>'RWebUser',
   // enable cookie-based authentication
  'allowAutoLogin'=>true,
  'loginUrl'=>array('/user/login'),

 ),

AssignementController

public function accessRules()
{
    return array(
        array('allow', // Allow superusers to access Rights

                        'actions'=>array(
                'view',
                'user',
                'revoke',
            ),
            'users'=>$this->_authorizer->getSuperusers(),
        ),
        array('deny', // Deny all users
            'users'=>array('*'),
        ),
    );
}

我需要你的帮助。请

请注意::我也在使用yii-user。 yii-user运行良好。

3 个答案:

答案 0 :(得分:2)

在您的控制器中,您需要将您的操作命名为执行功能。

  public function accessRules(){
    .......   
    array('allow', // allow authenticated user to perform 'create' and 'update' actions
                    'actions'=>array('create','update','districts','center'),
                    'users'=>array('@'),
    ......
    }

例如在上面的代码中,区和中心是动作 希望你能得到这个想法。

答案 1 :(得分:0)

我知道这是一个较旧的问题,但你要添加

public function filters()
{
    return array(
        'accessControl',
    );
}

到AssignementController? Yii需要它将函数accessRules()视为访问控制。

答案 2 :(得分:0)

设置您的" Yii :: app() - > user-> name";

试试这个

<?php
class UserIdentity extends CUserIdentity 
{
protected $_id;
const USER_INACTIVE = 3;

public function authenticate() 
{
    $p= Person::model()->findByUsername($this->username);
    if (empty($p))
        $this->errorCode = self::ERROR_USERNAME_INVALID;
    elseif (!CPasswordHelper::verifyPassword($this->password, $p->password))
        $this->errorCode = self::ERROR_PASSWORD_INVALID;
    else
    {
        $this->_id = $p->id;
        $this->username = $p->username;

        $this->errorCode = self::ERROR_NONE;
    }
    return !$this->errorCode;
}

public function getId() {
    return $this->_id;
}

}

该行&#34; $ this-&gt; username = $ p-&gt; username;&#34;;

希望得到这个帮助。