从用户中获取所有组 - sfDoctrineGuardPlugin

发布于 2024-11-17 22:05:23 字数 1437 浏览 2 评论 0原文

在 sfDoctrineGuardPlugin 中是:

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

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

  • @method Doctrine_Collection
    getGroups() 返回 当前记录的“组”集合

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

此返回:

 Doctrine_Collection data : Array( ) 

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

感谢您的帮助!

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?

  • @method Doctrine_Collection
    getGroups() Returns the
    current record's "Groups" collection

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

誰ツ都不明白 2024-11-24 22:05:23

请参阅 sfGuardSecurityUser 类: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();

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();
巴黎盛开的樱花 2024-11-24 22:05:23

您可以尝试使用查询来查找用户组:

$user_id = $this->getUser()->getGuardUser()->getId();
$groups = Doctrine_core::getTable('sfGuardGroup')->create_query('g')->innerJoin('g.users u with u.id= ?', $user_id);

you may try using a query to find groups of your user:

$user_id = $this->getUser()->getGuardUser()->getId();
$groups = Doctrine_core::getTable('sfGuardGroup')->create_query('g')->innerJoin('g.users u with u.id= ?', $user_id);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文