如何将 id 属性添加到 Zend Framework 表单? [英] How to add id attribute to Zend Framework form?

查看:33
本文介绍了如何将 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.

这篇关于如何将 id 属性添加到 Zend Framework 表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆