2013-12-01 6 views
1

Я новичок в yii. Я установил yii-права в защищенных/modules/правах согласно документации. Но нельзя использовать правильно. Что-то не хватает, что я не мог узнать. localhost/index.php/правая страница работает хорошо. Но когда я нажимаю «разрешения», «роли», «задачи», «операции». Он показываетYii Rights :: Ошибка 403 Вы не авторизованы для выполнения этого действия

«Ошибка 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 работает хорошо.

ответ

2

В вашем контроллере вы должны назвать свое действие для выполнения функции.

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

Например, в приведенном выше коде район и центр являются действиями.
Надеюсь, вы получите эту идею.

+0

Это не работает ::: my controller :: 'actions' => array ('view', 'user', 'revoke',), 'users' => $ this -> _ authorizer-> getSuperusers() , –

+0

, пожалуйста, помогите мне с правильным решением. Я не смог это исправить –

0

Я знаю, что это старая проблема, но вы добавляете

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

к AssignementController? Yii требует от него функции accessRules() для контроля доступа.

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; 
} 

}

строку "$ this-> имя пользователя = $ p-> имя пользователя;";

Надеюсь, что эта помощь.