0
我正在使用sfDoctrineGuard
插件作爲基地(裝置利用sfDoctrineGuard),所以在我的模塊我開發這個代碼的模塊上:創建新用戶關係不會保存,出了什麼問題?
class UsuariosForm extends sfGuardUserForm {
protected $current_user;
public function configure() {
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->current_user = sfContext::getInstance()->getUser()->getGuardUser();
$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'));
$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.')));
}
public function save($con = null) {
if (sfContext::getInstance()->getActionName() == "create" || sfContext::getInstance()->getActionName() == "new") {
$new_user = parent::save($con); /* @var $user sfGuardUser */
$new_user->addGroupByName('Monitor');
}
return $new_user;
}
}
第一個功能讓我有我自己的形式,而不是sfDoctrineGuard插件表單,第二個是覆蓋save()
方法,用於向我創建的新用戶添加默認組。我也想添加一個默認的idempresa
,你可能會注意到(在config()
函數中),但它不工作,也許我做錯了什麼或不知道。 idempresa
是存儲在sfGuardUserProfile
表中的字段,並且當然具有配置的關係等等。我的問題在於:在創建用戶時設置默認配置文件idempresa
的正確方法是什麼?