【发布时间】:2016-07-18 15:28:07
【问题描述】:
我正在尝试从我的 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
如果我刚刚将其更改为“Obligio”,为什么它会显示“必需”?有什么解决办法吗?
【问题讨论】:
-
其他定义的验证(min_length、max_length)是否正常工作?
-
它们看起来像这样:“Minimo 9 caracteresRequired”
标签: php html symfony-1.4