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データ:Array()

ユーザーがグループTESTに参加しているかどうかを確認するにはどうすればよいですか?

手伝ってくれてありがとう!

4

2 に答える 2

1

クエリを使用して、ユーザーのグループを検索してみてください。

$user_id = $this->getUser()->getGuardUser()->getId();
$groups = Doctrine_core::getTable('sfGuardGroup')->create_query('g')->innerJoin('g.users u with u.id= ?', $user_id);
于 2011-06-30T07:13:41.377 に答える
1

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();
于 2011-06-30T07:55:28.970 に答える