augustin
(Rmlodzki)
1
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
samdark
(Alexander Makarov)
2
You should allow delete for all logged in users and then check for admin with bizRules inside actionDelete.
augustin
(Rmlodzki)
3
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='???' />?
),
samdark
(Alexander Makarov)
4
Where are you going to get $params from?
augustin
(Rmlodzki)
5
from app()->user or from GET table
samdark
(Alexander Makarov)
6
You can get them in the bizRule itself.
xsirro
(Rossi Lazuardi)
8
Hi…
I have exactly the same problem, so… is it posible?
or what is the best implementation to extend accessRules function?
berza
(Twitcher)
9
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’,
weavora
(Yury Tolochko)
10
Simple code to assign role from user table to yii auth manager.
- config/main.php
'components' => array(
...
'authManager'=>array(
'class'=>'PhpAuthManager',
'defaultRoles' => array('guest'),
),
- 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)
- 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 