Symfony1 symfony 1.4:尝试替换默认值';必需的';消息

Symfony1 symfony 1.4:尝试替换默认值';必需的';消息,symfony1,translation,Symfony1,Translation,我正在尝试替换此验证器中的默认“必需”消息: $this->setValidator('email', new sfValidatorAnd(array( new sfValidatorEmail(array('required' => true, 'trim' => true)), new sfValidatorString(array('required' => true, 'max_length' => 80)), new sfValida

我正在尝试替换此验证器中的默认“必需”消息:

 $this->setValidator('email', new sfValidatorAnd(array(
   new sfValidatorEmail(array('required' => true, 'trim' => true)),
   new sfValidatorString(array('required' => true, 'max_length' => 80)),
   new sfValidatorDoctrineUnique(array(
     'model' => 'sfGuardUserProfile',
     'column' => 'email'
   ), array(
     'invalid' => 'An account with that email address already
exists. If you have forgotten your password, click "cancel", then "Reset
My Password."'))
 )));
但我不知道应该在哪里添加这样的内容:“必选”=> “你必须写你的电子邮件”)

有什么想法吗

Sf 1.4


Javi

您应该将其添加到数组()中,该数组应该是sfValidatorEmail构造函数的第二个参数

 $this->setValidator('email', new sfValidatorAnd(array(
   new sfValidatorEmail(array('required' => true, 'trim' => true)),
   new sfValidatorString(array('required' => true, 'max_length' => 80)),
   new sfValidatorDoctrineUnique(array(
     'model' => 'sfGuardUserProfile',
     'column' => 'email'
   ), array(
     'invalid' => 'An account with that email address already
exists. If you have forgotten your password, click "cancel", then "Reset
My Password."'))
 ),array(), array('required' => 'test custom message')));

您应该将其添加到数组()中,该数组应该是sfValidatorEmail构造函数的第二个参数

 $this->setValidator('email', new sfValidatorAnd(array(
   new sfValidatorEmail(array('required' => true, 'trim' => true)),
   new sfValidatorString(array('required' => true, 'max_length' => 80)),
   new sfValidatorDoctrineUnique(array(
     'model' => 'sfGuardUserProfile',
     'column' => 'email'
   ), array(
     'invalid' => 'An account with that email address already
exists. If you have forgotten your password, click "cancel", then "Reset
My Password."'))
 ),array(), array('required' => 'test custom message')));

您必须为SFValidator定义“必需”消息,并且:

$form->setValidator('email', new sfValidatorAnd(array(
   new sfValidatorEmail(array('required' => true, 'trim' => true)),
   new sfValidatorString(array('required' => true, 'max_length' => 80)),
   new sfValidatorDoctrineUnique(array(
     'model' => 'sfGuardUserProfile',
     'column' => 'email'
   ), array(
     'invalid' => 'An account with that email address already exists. If you have forgotten your password, click "cancel", then "Reset My Password."'))
 ), array(), array('required' => 'E-mail is required')));

SFValidator和执行清理,并负责设置错误消息。

您必须为SFValidator和定义“必需”消息:

$form->setValidator('email', new sfValidatorAnd(array(
   new sfValidatorEmail(array('required' => true, 'trim' => true)),
   new sfValidatorString(array('required' => true, 'max_length' => 80)),
   new sfValidatorDoctrineUnique(array(
     'model' => 'sfGuardUserProfile',
     'column' => 'email'
   ), array(
     'invalid' => 'An account with that email address already exists. If you have forgotten your password, click "cancel", then "Reset My Password."'))
 ), array(), array('required' => 'E-mail is required')));

SF验证程序和执行清理,并负责设置错误消息。

我尝试了您所说的,但它不起作用$此->setValidator('email',新的sfvalidator和(数组(新的sfvalidator电子邮件(数组('required'=>true,'trim'=>true),数组('required'=>'此字段为必填项))),奇怪…那你为什么接受我的答案?尝试删除sfValidatorString构造函数中的'required'=>true pari,一个'required'就足够了。如果你没有得到任何有用的答案,请悬赏,或者删除你的问题…如果你找到了自己问题的解决方案,请回答并接受自己的答案。关于你的问题,请尝试添加在SFValidator和构造函数中设置数组,这是第三个参数。我发布了一些代码来帮助您。这是因为必需的选项默认为true。我尝试了您所说的,但它不起作用…$this->setValidator('email',new sfvalidator)和(array)(new sfvalidator email(array('required'=>true,'trim'=>true)),array('required'=>'此字段为必填项')),奇怪…那你为什么接受我的答案?尝试删除sfValidatorString构造函数中的'required'=>true pari,一个'required'就足够了。如果你没有得到任何有用的答案,请悬赏,或者删除你的问题…如果你找到了自己问题的解决方案,请回答并接受自己的答案。关于你的问题,请尝试添加在SFValidator和构造函数中调用数组,这是第三个参数。我发布了一些代码来帮助您。这是因为必需的选项默认为true。