dongzha3058 2010-11-18 00:04
浏览 25
已采纳

sfguard上的高级/动态权限 - symfony

I have a symfony project and would like to add communities feature.

Everyone can open a community as an admin and invites people to join the community.

Admin has more permissions than a regular community user.

The thing is, I want to user Syfony's sfguarduser, sfguardgroup, sfguardpermission

  1. Does it make any sense to use the sfguard architecture for that purpose?
  2. how do I check if a specific user has a spcecific permission on a specific group?
  • 写回答

2条回答 默认 最新

  • dsyq40772 2010-11-18 03:19
    关注

    Hey, this will help you a little ;)

    Inside the action :

      class myAccountActions extends sfActions
    {
      public function executeDoThingsWithCredentials()
      {
        $user = $this->getUser();
    
        // Check if the user has a credential
        echo $user->hasCredential('foo');                      =>   true
    
        // Check if the user has both credentials
        echo $user->hasCredential(array('foo', 'bar'));        =>   true
    
        // Check if the user has one of the credentials
        echo $user->hasCredential(array('foo', 'bar'), false); =>   true
    
        // Remove a credential
        $user->removeCredential('foo');
        echo $user->hasCredential('foo');                      =>   false
    
        // Remove all credentials (useful in the logout process)
        $user->clearCredentials();
        echo $user->hasCredential('bar');                      =>   false
      }
    }
    

    Inside the layer :

         <?php if ($sf_user->hasCredential('section3')): ?>
      ....
      <?php endif; ?>
    

    You might consider using in addition :

    if($user->hasGroup('SOME_GROUP')) 
    

    Source : Symfony inside the layer

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大