0

I have a table that has a sfGuardGroup column so when a user logs in, they can only see the records users in their group have made.

When creating a record I want to have a select box for the sfGuardGroup that only contains the groups that the logged in user is a member of.

Anyone know how to do this please?

Thanks

dazpinto
  • 105
  • 1
  • 9

1 Answers1

0

In the form::configure

  1. get user: use sfContex::getInstance()->getUser() (easy way, not recommend) or inject sfUser from controller as option

    $this->form = new myAwesomeUserForm(array(),array('user'=>$this->getUser()));

  2. Use sfWidgetFormChoice

  3. Use sfGuardSecurityUser::getGroups ($user->getGroups) to set choices for sfWidgetFormChoice widget. Here $user is instance of myUser>sfGuardSecurityUser
  4. Do not forget validator
cuhuak
  • 498
  • 4
  • 9
  • Thanks for replying, sorry if I sound a bit dumb, but is this what you mean: [code] public function configure() { $user = sfContext::getInstance()->getUser(); $this->widgetSchema['sfGuardGroup'] = new sfWidgetFormDoctrineChoice(array('model' => sfGuardSecurityUser::getGroups($user->getGroups), 'add_empty' => false)); }[code] – dazpinto Mar 18 '11 at 15:09
  • almost yes. You do not need to use sfWidgetFormDoctrineChoice, Just use sfWidgetFormChoice – cuhuak Mar 18 '11 at 17:24
  • I am getting the error `code` Strict Standards: Non-static method sfGuardSecurityUser::getGroups() should not be called statically, assuming $this from incompatible context in C:\xampp\htdocs\DSMS\lib\form\doctrine\slideForm.class.php on line 16 Notice: Undefined property: myUser::$getGroups in C:\xampp\htdocs\DSMS\lib\form\doctrine\slideForm.class.php on line 16 `code` Is it right that I'm putting it in lib\form\doctrine\***Form.class.php ? – dazpinto Mar 18 '11 at 19:36
  • You should use $user->getGroups() method. – cuhuak Mar 21 '11 at 04:59
  • it gets all the groups that the user is in now, however it won't save, it says sfGuardGroup is invalid – dazpinto Mar 25 '11 at 21:26
  • Please show some of your current code, configuring the form widget and best resulting html form template. – domi27 Sep 07 '11 at 05:45