本文介绍了从Users - sfDoctrineGuardPlugin获取所有组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sfDoctrineGuardPlugin是:

  sfGuardUser:
actAs:[Timestampable]
列:
first_name:string(255)
last_name:string(255)
//
索引:
is_active_idx:
fields:[is_active]
关系:
组:
类:sfGuardGroup
本地:user_id
外观:group_id
refClass:sfGuardUserGroup
foreignAlias:用户



sfGuardGroup:
actAs:[Timestampable]
列:
名称:
类型:string(255)
unique:true
描述:string(1000)
关系:
用户:
类:sfGuardUser
refClass:sfGuardUserGroup
local:group_id
foreign:user_id
foreignAlias:Groups

sfGuardUserGroup:
选项:
symfony:
form:false
过滤器:false
actAs:[Timestampable]
列:
u ser_id:
类型:integer
primary:true
group_id:
类型:integer
primary:true
关系:
用户:
class:sfGuardUser
local:user_id
onDelete:CASCADE
组:
类:sfGuardGroup
本地:group_id
onDelete:CASCADE

这是多对多关系,我如何获取所有用户组?

我做:

  $ this-> groups = $ this-> getUser() - > getGuardUser() - > getGroups(); 

此返回:

 Doctrine_Collection data:Array()

我如何检查用户是否在组TEST?



解决方案

请参阅sfGuardSecurityUser类:

  if($ this-> getUser() - > hasGroup('TEST')){ 
//如果用户在组TEST
} // end if

//获取所有组

$ userGroups = $ this->的getUser() - > getGroups();


In sfDoctrineGuardPlugin is:

sfGuardUser:
  actAs: [Timestampable]
  columns:
    first_name: string(255)
    last_name: string(255)
    //
  indexes:
    is_active_idx:
      fields: [is_active]
  relations:
    Groups:
      class: sfGuardGroup
      local: user_id
      foreign: group_id
      refClass: sfGuardUserGroup
      foreignAlias: Users



sfGuardGroup:
  actAs: [Timestampable]
  columns:
    name:
      type: string(255)
      unique: true
    description: string(1000)
  relations:
    Users:
      class: sfGuardUser
      refClass: sfGuardUserGroup
      local: group_id
      foreign: user_id
      foreignAlias: Groups

sfGuardUserGroup:
  options:
    symfony:
      form:   false
      filter: false
  actAs: [Timestampable]
  columns:
    user_id:
      type: integer
      primary: true
    group_id:
      type: integer
      primary: true
  relations:
    User:
      class: sfGuardUser
      local: user_id
      onDelete: CASCADE
    Group:
      class: sfGuardGroup
      local: group_id
      onDelete: CASCADE

This is relation many to many and how can i get all groups of User?

i make:

$this->groups = $this->getUser()->getGuardUser()->getGroups();

this return:

 Doctrine_Collection data : Array( ) 

how can i check whether the user is on group TEST?

Thanks for help!

解决方案

See the sfGuardSecurityUser class: https://github.com/Garfield-fr/sfDoctrineGuardPlugin/blob/master/lib/user/sfGuardSecurityUser.class.php

if ($this->getUser()->hasGroup('TEST')) {
    //if user is on group TEST
}//end if

// get all groups

$userGroups = $this->getUser()->getGroups();

这篇关于从Users - sfDoctrineGuardPlugin获取所有组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 03:40