如何更改symfony表单错误消息?

Ben*_*ier 2 php symfony1 symfony-1.4

我正在使用symfony 1.4.

我有一个这样的表格:

验证器:

$this->setValidator('name', new sfValidatorString(array('required' => true)));    
Run Code Online (Sandbox Code Playgroud)

视图:

<?php echo $form['name']->renderError() ?>
Run Code Online (Sandbox Code Playgroud)

如何更改默认的"必需"错误消息,例如"此字段是否必需"?

编辑:另外,我如何摆脱<ul><li>生成的标签renderError().方法 ?我只想显示文本,没有额外的标记.


注意:这是一个显而易见的问题,但由于我花了很长时间才发现,我认为这个问题在这里被问到了.

ars*_*nik 5

1.更改所需的消息:

new sfValidatorString(
    array(
        'required' => true,
    ), 
    array(
        'required'=>'You custom required message'
    ));
Run Code Online (Sandbox Code Playgroud)

2.创建一个新的格式化程序类.

3.重新定义所需的属性.

<?php
class myWidgetFormSchemaFormatter extends sfWidgetFormSchemaFormatter
{

  protected
    $rowFormat                 = '',
    $helpFormat                = '%help%',
    $errorRowFormat            = '%errors%',
    $errorListFormatInARow     = "  <ul class=\"error_list\">\n%errors%  </ul>\n",
    $errorRowFormatInARow      = "    <li>%error%</li>\n",
    $namedErrorRowFormatInARow = "    <li>%name%: %error%</li>\n",
    $decoratorFormat           = '',
    $widgetSchema              = null,
    $translationCatalogue      = null;
Run Code Online (Sandbox Code Playgroud)

4.在symfony表单的configure方法中添加

$oDecorator = new myWidgetFormSchemaFormatter($this->getWidgetSchema());
$this->getWidgetSchema()->addFormFormatter('myCustom', $oDecorator);
$this->getWidgetSchema()->setFormFormatterName('myCustom');
Run Code Online (Sandbox Code Playgroud)