내 등록 양식을 사용하여 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.')));
}
가 지금은 사용자가 로그인하는 것과 같은 그룹 (들)과 그 새 사용자를 작성해야하지만 방법을 몰라. 나는 this post을 읽었지 만, getGroups()
을 사용하면 기본값 인 groups_list
을 설정한다는 의미일까요? 이 작업을 수행하는 가장 좋은 방법은 무엇입니까?
좋은 대답 +1 이제 모든 게시물을 메인 포스트로 저장하는 대신, 그룹에 "그룹 1"이라고 말하면서 저장할 수 있습니다. 방법? – Reynier
감사합니다. @Reynier! 그룹 이름을 안다면'foreach' 루프를'$ new_user-> addGroupByName ('당신의 그룹 이름');' – moote
우수로 대체하십시오. 한가지 마지막 질문 :'sfGuardUserProfile' 테이블과의 관계가 있습니다. 새로운 생성 된 사용자를 위해'$ id_empresa'를 설정하는 것을 좋아합니다. 어떻게? 'save()'메소드에서'BasesfGuardUser' 클래스에있는'setSfGuardUserProfile()'메소드에 접근 할 수 있습니까? – Reynier