Zend Form Decorators用于嵌入标签和元素

时间:2013-02-08 02:52:05

标签: css zend-framework decorator

我完全不知道如何在Zend中使用装饰器!

如果您创建一个没有装饰器的基本简单表单,标签将进入DT,元素将进入DD。他们都是一个接一个地去。

那么我如何制作它以使每个标签及其相应的元素也进入div内?

非常感谢! Kousha

1 个答案:

答案 0 :(得分:0)

我爱装饰者!但他们很难掌握。你的问题很容易,这是一件好事。

我在表单中使用了一个函数

public function getElementDecorators()
{
    return array(
        'ViewHelper',
        'Errors',
        array('Description', array('tag' => 'p', 'class' => 'description')),
        array('HtmlTag', array('tag' => 'dd', 'id'  => array('callback' => array(get_class($this), 'resolveElementId')))),
        array('Label', array('tag' => 'dt')),
        array(array('elementContainer' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element-container')),
    );
}

然后对于表单中的每个元素,我都是这样创建的。

$this->addElement('Text', 'wordup', array(
    'label' => 'Put your words here',
    'attribs' => array('class' => 'textbox-fancy'),
    'decorators' => $this->getElementDecorators()
));