自定义错误消息无法正常显示

时间:2016-07-18 15:28:08

标签: php html symfony-1.4

我正在尝试从我的CustomForm.class.php中获取一个自定义错误消息,它位于app / module / modulename / lib中但是我得到另一个(也许是Base的默认值)...就像原始邮件错误无法覆盖......

BaseClientForm.class.php

abstract class BaseClientForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'phonenumber'           => new sfWidgetFormInputText()
    ));

    $this->setValidators(array(

      'phonenumber'           => new sfValidatorString(array('max_length' => 20))
    ));

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

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

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'Client';
  }

}

在ClientForm.class.php中:

class ClientForm extends BaseClientForm {

    public function configure() {

        $this->validatorSchema['phonenumber'] = new sfValidatorAnd(array(new sfValidatorString(array('min_length' => 9, 'max_length' => 9, 'required' => true),array('min_length' => 'Mínimo 9 caracteres', 'max_length' => 'Máximo 9 caracteres', 'required' => 'Obligatorio')), new sfValidatorRegex(array('pattern' => '([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])','must_match' => true))));

    }
}

在我的模板中:

<?php if($form['phonenumber']->hasError()): ?>
 <p class="error"><?php echo $form['phonenumber']->getError()->getMessage() ?></p>
<?php endif ?>

结果:

Required

如果我刚将其更改为“Obligatorio”,为什么显示“必需”?任何解决方案?

1 个答案:

答案 0 :(得分:0)

所以,调试框架我意识到你必须将///// ***** GIT ***** ///// gulp.task('tag:commit', function () { var version = pjson.version; console.log(colors.bgWhite.black.bold(' \nTagging the version ' + version + ' \n')); return run('git tag ' + version).exec(); }); 消息传递给你的required

sfValidatorAnd

此外,默认情况下,您的所有字段均为$this->validatorSchema['phonenumber'] = new sfValidatorAnd(array( new sfValidatorString(array('min_length' => 9, 'max_length' => 9), array('min_length' => 'Mínimo 9 caracteres', 'max_length' => 'Máximo 9 caracteres')), new sfValidatorRegex(array('pattern' => '([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])','must_match' => true)) ), array(), array('required' => 'My required message')); ,因此无需明确声明字段required