dongnong3799 2012-07-13 19:43
浏览 63
已采纳

在Yii Rbac扩展名权限中为管理员创建用户分配用户角色

I have installed rights as suggested by most people, its easy to implement Role based access control. but I am stuck at a problem..

I need to assign a user a role from admin, who can change their roles..etc..

As rights doesn't create models for the tables I cant insert in them..and as such there is no documentation, how to do it...

  • 写回答

4条回答 默认 最新

  • duanmanmian7589 2012-07-14 04:20
    关注

    First you need a drop-down of all roles in the system, for admin to select..

    <?php
    if (Yii::app()->user->isSuperuser) {
           $all_roles=new RAuthItemDataProvider('roles', array( 
        'type'=>2,
        ));
          $data=$all_roles->fetchData();
    ?>
        <div>
            <label for="type_id">Type</label>
            <?php echo CHtml::dropDownList("Type",'',CHtml::listData($data,'name','name'));?    > 
        </div>
    <?php
    }
    ?>
    

    And then on backend you'll need to asign a role to the user based on the Type values selected by the admin...

    if(Yii::app()->user->isSuperuser)
        $type=$_POST['Type'];
    else
        $type='User';
    
    $authorizer = Yii::app()->getModule("rights")->authorizer;
    $authorizer->authManager->assign($type, $model->id);
    

    This code checks if the registration was from admin, then it sets the role selected by the admin, else it sets User as role, ie, same code will work for admin user create and normal signup..

    There are such other issues in Rights which are not preperly documented...I have written some in my blog.. My blog post about Yii Rights

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助