how to pass parameters to role in accessRules()?

I use rbac. Some roles use bizRules. I use it in accessRules() function in controllers. How to pass parameters for the roles into accessRules()?




  array('allow',

                'actions'=>array('delete'),

                'roles'=>array('admin'), //WHERE PUT PARAMETERS FOR BIZRULES?

            ),



regards,

augustin

You should allow delete for all logged in users and then check for admin with bizRules inside actionDelete.

Is it impossible to do it only in accessRules()? E.g. something like this would be nice:




array('allow',

                'actions'=>array('delete'),

                'roles'=>array(array('role1',$params),array('role2',$params)), //<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?

            ),

Where are you going to get $params from?

from app()->user or from GET table

You can get them in the bizRule itself.

:)

Hi…

I have exactly the same problem, so… is it posible?

or what is the best implementation to extend accessRules function?

i have the same problem, may be this will help you

// optional, a PHP expression whose value indicates whether this rule applies

// This option is available since version 1.0.3.

‘expression’=>’!$user->isGuest && $user->level==2’,

Simple code to assign role from user table to yii auth manager.

  1. config/main.php

'components' => array(

...

    'authManager'=>array(

      'class'=>'PhpAuthManager',

      'defaultRoles' => array('guest'),

    ),

  1. components/PhpAuthManager.php

<?php

class PhpAuthManager extends CPhpAuthManager {

    public function init() {

        if($this->authFile === null) {

            $this->authFile = Yii::getPathOfAlias('application.config.auth').'.php';

        }


        parent::init();

        

        if(!Yii::app()->user->isGuest) {            

            $this->assign(Yii::app()->user->role, Yii::app()->user->id);

        }

    }

}

Note: please, be sure that you could get Yii::app()->user->role (See WebUser.php)

  1. config/auth.php

<?php


return array(


  // roles

  'guest' => array(

    'type'        => CAuthItem::TYPE_ROLE,

    'description' => 'Guest',

    'bizRule'     => null,

    'data'        => null),

  

  User::ROLE_MEMBER => array(

    'type'        => CAuthItem::TYPE_ROLE,

    'description' => 'Member',

    'children'    => array('guest'),

    'bizRule'     => null,

    'data'        => null

  ),


  User::ROLE_ADMINISTRATOR => array(

    'type'        => CAuthItem::TYPE_ROLE,

    'children'    => array(User::ROLE_MEMBER),

    'description' => 'Admin',

    'bizRule'     => null,

    'data'        => null),

);

That’s all. Now ‘roles’=>array(‘admin’), should work :)