Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何更改symfony表单错误消息?_Php_Symfony1_Symfony 1.4 - Fatal编程技术网

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

Php 如何更改symfony表单错误消息?,php,symfony1,symfony-1.4,Php,Symfony1,Symfony 1.4,我使用的是symfony1.4 我有一张这样的表格: 验证程序: $this->setValidator('name', new sfValidatorString(array('required' => true))); <?php echo $form['name']->renderError() ?> 查看: $this->setValidator('name', new sfValidatorString(array('required'

我使用的是symfony1.4

我有一张这样的表格:

验证程序:

$this->setValidator('name', new sfValidatorString(array('required' => true)));    
<?php echo $form['name']->renderError() ?>
查看:

$this->setValidator('name', new sfValidatorString(array('required' => true)));    
<?php echo $form['name']->renderError() ?>

如何将默认的“required”错误消息更改为例如“This field is required”

编辑:另外,如何去除由
渲染器()生成的
  • 标记。方法?我只想显示文本,不需要额外的标记


    注:这是一个显而易见的问题,但由于我花了很长时间才找到答案,我认为这个问题不适合在这里提出

    new sfValidatorString(array('required' => true), array('required'=>'This field is required'))
    

    您可以通过扩展sfWidgetFormSchemaFormatter来创建自定义WidgetFormSchemaFormatter,以格式化表单输出。

    1.更改所需消息:

    new sfValidatorString(
        array(
            'required' => true,
        ), 
        array(
            'required'=>'You custom required message'
        ));
    
    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;