【问题标题】:Table Decorators on Zend Framework FormZend 框架表单上的表装饰器
【发布时间】:2010-02-24 09:04:14
【问题描述】:

我创建了一个表格,它装饰成表格

这是我的装饰代码

$this->setElementDecorators(array(
            'ViewHelper',
            'Errors'
            array(array('data'=>'HtmlTag'),
            array('tag'=>'td','class'=>'element')),
            array('Label',array('tag'=>'td')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr')),

    ));

$this->setDecorators(array(
            'FormElements',
            array('HtmlTag',array('tag'=>'table')),
            'Form'
        ));

它工作正常, 现在我也想要错误消息装饰 我要改什么代码?

【问题讨论】:

  • 我没有足够的声誉,无法编辑您的代码。

标签: zend-framework zend-form zend-form-element


【解决方案1】:

这是一种相当复杂的方法。我也为装饰器添加了类,因此您可以为它们设置与您的示例不同的样式。

// To be assigned at the beginning of your form class.

    public $elementDecorators = array(
    'ViewHelper',
    'Errors',
    array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'col2')),
    array('Label', array('tag' => 'td','class'=>'taR')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr','class' => 'rowA')),
    );

$this->addElement('ValidationTextBox', 'name', array(
            'decorators' => $this->elementDecorators,
            'validators' => array(                                 
                                array('regex',  false,'/^[a-zA-Z ]+$/')
                            ),
            'label' => $this->translator->translate ( 'Name' ) . ' : ',
            'required' => true,
            'trim' => true,
            'propercase' => true,
             'regExp' => '[a-zA-Z ]+',
                'invalidMessage' => $this->translator->translate ( 'Name - Must be alpha numeric.' )
            )
            );

【讨论】:

  • 我想在不在它们下面的元素旁边显示错误消息,我该如何装饰它们
【解决方案2】:

如果你想在一个地方显示所有错误,你应该从每个元素中删除 Error 装饰器,然后添加 formErrors 装饰器。这是来自How to remove Zend Form error messages?的示例

$form->setDecorators(array(
    'FormElements',
    new Zend_Form_Decorator_FormErrors(array
        (
            'ignoreSubForms' => true,
            'markupElementLabelEnd' => '</b>',
            'markupElementLabelStart' => '<b>',
            'markupListEnd' => '</div>',
            'markupListItemEnd' => '</span>',
            'markupListItemStart' => '<span>',
            'markupListStart' => '<div id="Form_Errors">'
        )
    ),
    'Form'
)); 

【讨论】:

    猜你喜欢
    • 2011-07-13
    • 2011-08-08
    • 2011-05-20
    • 1970-01-01
    • 2012-04-10
    • 2011-01-10
    • 1970-01-01
    • 2012-10-23
    • 2010-11-12
    相关资源
    最近更新 更多