如何将 id 属性添加到 Zend Framework 表单?

问题描述:

我有一个简单的类,它用 2 个元素扩展 Zend_Form:

I have simple class which extends Zend_Form with 2 elements:

class Application_Form_Player extends Zend_Form
{
    public function init()
    {
        $this->addElement('text', 'firstName', array(
                'label' => $this->getView()->translate('First name') . ' (' . $this->getView()->translate('imaginary') . ')',
                'required' => true,
                'filters' => array('StringTrim'),
                'validators' => array(array('StringLength', false, array(1, 256)))
            )
        );
        $this->addElement('text', 'lastName', array(
                'label' => $this->getView()->translate('Last name') . ' (' . $this->getView()->translate('imaginary') . ')',
                'required' => true,
                'filters' => array('StringTrim'),
                'validators' => array(array('StringLength', false, array(1, 256)))
            )
        );
    }

}

是否有 Zend_Form 方法可用于将id"属性添加到此类创建的 HTMLdl"中?

Is there a Zend_Form method that I can use to add "id" attribute to the HTML "dl" created by this class?

这是我想要添加 id 属性的结果 HTML dl:

This is resulting HTML dl to which I want to add id attribute:

<dl class="zend_form">
...
</dl>

$this->setAttrib('id', 'someId');, this will help you where $this 是当前类的对象.

$this->setAttrib('id', 'someId');, this would help you where $this being the object of your current class.