Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. assign a user a role from admin creates a user, in Yii Rbac extension Rights
  2. <?php
  3. if (Yii::app()->user->isSuperuser) {
  4.        $all_roles=new RAuthItemDataProvider('roles', array(
  5.     'type'=>2,
  6.     ));
  7.       $data=$all_roles->fetchData();
  8. ?>
  9.     <div>
  10.         <label for="type_id">Type</label>
  11.         <?php echo CHtml::dropDownList("Type",'',CHtml::listData($data,'name','name'));?    >
  12.     </div>
  13. <?php
  14. }
  15. ?>
  16.        
  17. if(Yii::app()->user->isSuperuser)
  18.     $type=$_POST['Type'];
  19. else
  20.     $type='User';
  21.  
  22. $authorizer = Yii::app()->getModule("rights")->authorizer;
  23. $authorizer->authManager->assign($type, $model->id);
  24.        
  25. Yii::app()->authManager->assign($role, $userid);