donglu8334 2013-11-05 14:09
浏览 22
已采纳

一些帮助根据权限分解代码

Morning,

with this code (symfony mask builder)

     MASK_VIEW         = 1;          // 1 << 0
     MASK_CREATE       = 2;          // 1 << 1
     MASK_EDIT         = 4;          // 1 << 2
     MASK_DELETE       = 8;          // 1 << 3
     MASK_UNDELETE     = 16;         // 1 << 4
     MASK_OPERATOR     = 32;         // 1 << 5
     MASK_MASTER       = 64;         // 1 << 6
     MASK_OWNER        = 128;

for a given resource,i store permission (int) by additionning theses permissions,with a basic example, i add: view, create, edit, will give 7.

So my question is how to "split" this 7 to retrieve thoses granted permissions.

i have a working code, with "if" and "else", but that's just ugly, so any "beautiful mind" would help on this ?

  • 写回答

1条回答 默认 最新

  • dongluan2612 2013-11-05 14:14
    关注

    This not something you will do it with split but with bitwise operartor. Just chek this out:

    If the values are coming from database you also can refer to:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频