0
我想用我自己的註冊表格向sfDoctrineGuard表添加新用戶。這是配置功能我做:用同一個用戶組創建新用戶
public function configure() {
// Remove all widgets we don't want to show
unset(
$this['is_super_admin'], $this['updated_at'], $this['groups_list'], $this['permissions_list'], $this['last_login'], $this['created_at'], $this['salt'], $this['algorithm']
);
$id_empresa = sfContext::getInstance()->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
$this->setDefault('idempresa', $id_empresa);
$this->validatorSchema['idempresa'] = new sfValidatorPass();
$this->widgetSchema['first_name'] = new sfWidgetFormInputText(array(), array('class' => 'input-block-level'));
$this->widgetSchema['last_name'] = new sfWidgetFormInputText(array(), array('class' => 'input-block-level'));
$this->widgetSchema['username'] = new sfWidgetFormInputText(array(), array('class' => 'input-block-level'));
$this->widgetSchema['email_address'] = new sfWidgetFormInputText(array(), array('class' => 'input-block-level'));
$this->widgetSchema['password'] = new sfWidgetFormInputPassword(array(), array('class' => 'input-block-level'));
$this->widgetSchema['password_confirmation'] = new sfWidgetFormInputPassword(array(), array('class' => 'input-block-level'));
// Setup proper password validation with confirmation
$this->validatorSchema['password']->setOption('required', true);
$this->validatorSchema['password_confirmation'] = clone $this->validatorSchema['password'];
$this->widgetSchema->moveField('password_confirmation', 'after', 'password');
$this->mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_confirmation', array(), array('invalid' => 'The two passwords must be the same.')));
}
現在我需要創造這些新用戶與用戶登錄同一組(S),但我不知道怎麼辦。我讀this post,但不知道如果使用getGroups()
將做的工作,我的意思是設置groups_list
默認,任何建議?什麼是最好的方法來做到這一點?
好的答案+1,現在我想知道,而不是保存所有組作爲主要職位說,只是爲了保存讓我們說組稱爲「組1」,這是可能的嗎?怎麼樣? – Reynier
謝謝@Reynier!如果你知道組名,只需用'$ new_user-> addGroupByName('你的組名')替換'foreach';' – moote
優秀,它的工作原理。最後一個問題:我和'sfGuardUserProfile'表有關係,我也想爲新創建的用戶設置'$ id_empresa',怎麼樣?我可以通過save()方法訪問'BasesfGuardUser'類中的'setSfGuardUserProfile()'方法嗎? – Reynier