setValidator () en clase de acción

I have one issue when I am trying to use setValidator() (¿No estás registrado como setValidators) in action class file.

this is my base form class code..

public function setup()
  {
    $this->setWidgets(array(
      'id'         => new sfWidgetFormInputHidden(),
      'name'       => new sfWidgetFormInputText(),
      'age'        => new sfWidgetFormChoice(array('choices' => array('21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30'))),
      'gender'     => new sfWidgetFormChoice(array('choices' => array('Male' => 'Male', 'Female' => 'Female'))),
      'email'      => new sfWidgetFormInputText(),
      'salt'       => new sfWidgetFormInputText(),
      'password'   => new sfWidgetFormInputPassword(array('type' => 'password')),
      'created_at' => new sfWidgetFormDateTime(),
      'updated_at' => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(      
      'id'         => new sfValidatorPass(),    
      'name'       => new sfValidatorString(array('required' => true)),
      'age'        => new sfValidatorPass(),      
      'gender'     => new sfValidatorChoice(array('choices' => array('Male','Female'))),
      'email'      => new sfValidatorEmail(array('required' => true)),
      'password'   => new sfValidatorString(array('required' => true)),
      'created_at' => new sfValidatorDateTime(),
      'updated_at' => new sfValidatorDateTime(),
    ));

    $this->widgetSchema->setNameFormat('signin[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);


    //$this->validatorSchema->setPostValidator(new sfUserValidate());

    $this->setupInheritance();

    parent::setup();
  }

this is my action class code..

public function executeNewuser($request)
  {
      $this->form = new UsersForm();
      $this->form->getWidgetSchema()->setNameFormat('users[%s]');

      //$this->form->setValidators(array('name' => new sfValidatorDoctrineUnique(array('model'  => 'Users','column' => 'name'))));

      $this->form->setValidator(array('name' => new sfValidatorDoctrineUnique(array('model'  => 'Users','column' => 'name'))));



      if($request->isMethod('post'))
      {
        $this->form->bind($request->getParameter('users'));
        if($this->form->isValid())
        {      
            echo "Hello";exit;
        }  

      }
  }

estoy recibiendo el siguiente error

Catchable fatal error: Argument 2 passed to sfForm::setValidator() must be an instance of sfValidatorBase, none given, called in /home/hardik/web/demo/apps/frontend/modules/user/actions/actions.class.php on line 77

i just need to override validator for name field in action class.

preguntado el 08 de noviembre de 11 a las 12:11

1 Respuestas

Your syntax is wrong. Look at setValidator's signature. You should be doing this:

$this->form->setValidator(
  'name', 
  new sfValidatorDoctrineUnique(array('model'  => 'Users','column' => 'name')));

respondido 08 nov., 11:16

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.