doulan7166 2014-03-21 10:42
浏览 58

Yii - 自定义访问控制标准

I am developing an application using Yii framework. I am in a situation where I want to create a custom filter. For example, the normal filters are like:

    array('allow',  // allow all users to perform 'index' and 'view' actions
            'actions'=>array('view'),
            'users'=>array('*'),
        ),

Now, in the array index for users you can only put admin, @ or *. I wanted to know if it's possible to customize it in a way that not only these 3 parameters are used. In my system, I have a set of user roles (which I have created in the database). There's one user called whose role is 'general'. He can only view some pages. There's another type of user with the role of 'business_admin' whose role can allow him to access his pages as well as the 'general' user's pages.

Could this be implemented by having:

    array('allow',
         'actions'=>'the_admin_actions',
         'users'=>'business_admin',
     ),

Please help!

  • 写回答

1条回答 默认 最新

  • doushe2513 2014-03-21 13:26
    关注

    That wont work as you need users to be either ? * or @ unless you have an actual username called business_admin like the defualt Yii config has a hard coded 'admin' username. You can set up RBAC though and then add 'roles' => 'business_admin'

    This answer may help you yii RBAC and yii controllers access rules

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?