2013-06-18 1 views
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() 함수에서) 알 수 있듯이 추가하고 싶지만 작동하지 않습니다. 어쩌면 내가 잘못한 것을하고 있거나 모릅니다. idempresasfGuardUserProfile 테이블에 저장된 필드이며 물론 관계가 구성되어 있습니다. 내 질문은 여기에 : 사용자를 만들 때 프로필을 설정하기 위해 기본 idempresa을 설정하는 올바른 방법은 무엇입니까?

답변

1

당신은 다시 $new_user 객체를 저장할 수 있습니다

$new_user->save($con)은 또한 당신은 저장() 메소드에 ACTION_NAME를 확인하지 않아도, 당신은 객체가 새로운 여부를 확인할 수 있습니다. Objectform에는이를위한 메소드가 있습니다.

<?php 
    ... 
    public function save($con = null) 
    { 
     $new_user = parent::save($con); 
     if($this->isNew()) 
     { 
      $new_user->addGroupByName('Monitor'); 
      $new_user->save($con); //this saves the group 
     } 
     return $new_user; 
    } 
    ... 
관련 문제