如何将 id 属性添加到 Zend Framework 表单?
How to add id attribute to Zend Framework form?
我有一个简单的 class,它用 2 个元素扩展了 Zend_Form:
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" 属性添加到此 class 创建的 HTML "dl"?
这是我要添加 id 属性的 HTML dl 的结果:
<dl class="zend_form">
...
</dl>
$element = new Zend_Form_Element_Text('something');
$element->setAttrib('id','myId')
->setLabel('myLabel')
->setRequired(true);
$this->addElements(array(
$element
));
您可以将 validators
和 filters
与 addValidator()
和 addFilter()
添加到。
$this->setAttrib('id', 'someId');
,这将帮助您将 $this
作为当前 class.
的对象
我有一个简单的 class,它用 2 个元素扩展了 Zend_Form:
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" 属性添加到此 class 创建的 HTML "dl"?
这是我要添加 id 属性的 HTML dl 的结果:
<dl class="zend_form">
...
</dl>
$element = new Zend_Form_Element_Text('something');
$element->setAttrib('id','myId')
->setLabel('myLabel')
->setRequired(true);
$this->addElements(array(
$element
));
您可以将 validators
和 filters
与 addValidator()
和 addFilter()
添加到。
$this->setAttrib('id', 'someId');
,这将帮助您将 $this
作为当前 class.