如何在Zend中为装饰器设置标签

时间:2013-10-24 16:29:27

标签: php jquery html zend-framework

我需要在Zend框架中设置我的复选框样式,在我的zend表单填充标签的那一刻:

<dt id="disabled-label"><label for="disabled" class="optional">Disabled Access</label></dt>
<dd id="disabled-element">
<input type="hidden" name="disabled" value="0"><input type="checkbox" name="disabled" id="disabled" value="1"></dd>

我需要输出:

残疾人通道          

下面是zend表单,显然我只给出了上面HTML的较短版本:

    public function searchForm() {
        $sp = $this->createElement('checkbox', 'sw')
                ->setOptions(
                array(
                    'label' => 'Swimming Pool',
                )
        );

        $spa = $this->createElement('checkbox', 'spa')
                ->setOptions(
                array(
                    'label' => 'Spa ',
                )
        );

        $gym = $this->createElement('checkbox', 'gym')
                ->setOptions(
                array(
                    'label' => 'Gym ',
                )
        );

        $wifi = $this->createElement('checkbox', 'wifi')
                ->setOptions(
                array(
                    'label' => 'Wifi ',
                )
        );

        $parking = $this->createElement('checkbox', 'parking')
                ->setOptions(
                array(
                    'label' => 'On-Site Parking ',
                )
        );

        $golf = $this->createElement('checkbox', 'golf')
                ->setOptions(
                array(
                    'label' => 'Golf ',
                )
        );

        $wp = $this->createElement('checkbox', 'wp')
                ->setOptions(
                array(
                    'label' => 'Wedding Packages ',
                )
        );

        $cc = $this->createElement('checkbox', 'cc')
                ->setOptions(
                array(
                    'label' => 'Civil Ceremonies ',
                )
        );

        $city = $this->createElement('checkbox', 'city')
                ->setOptions(
                array(
                    'label' => 'City Central ',
                )
        );

        $oot = $this->createElement('checkbox', 'oot')
                ->setOptions(
                array(
                    'label' => 'Out Of Town ',
                )
        );

        $disabled = $this->createElement('checkbox', 'disabled')
                ->setOptions(
                array(
                    'label' => 'Disabled Access ',
                )
        );

        $submit = $this->createElement('submit', 'submit')
                                ->setOptions
                                (array('label' => 'SEARCH OUR HOTELS',
                                       'class' => 'f-left btn-purple icon'
                                    ));

        $this->addElement($sp)
                ->addElement($spa)
                ->addElement($gym)
                ->addElement($wifi)
                ->addElement($parking)
                ->addElement($golf)
                ->addElement($wp)
                ->addElement($cc)
                ->addElement($city)
                ->addElement($oot)
                ->addElement($disabled)
                ->addElement($submit);
    }

}

2 个答案:

答案 0 :(得分:0)

您可以使用

删除dtddWrapper装饰器
$element->removeDecorator('DtDdWrapper');

但它仍会添加<label for...>代码。

或者您可以添加自己的装饰器......有关详细信息,请参阅this post

答案 1 :(得分:0)

使用:->setLabelAttributes(array(''))