Zend_Form - add CSS Class :: How can I add css class to label in Zend_Form?

馋奶兔 提交于 2019-12-24 09:16:21

问题


How can I add css class to label in Zend_Form?

This is html way:

<dt><label for="foo" class="label-design">Foo</label></dt>

How can I write above row with Zend_Form?

(I know how to write label but i dont know how can i add ccss class.

$model = new Zend_Form_Element_Text('model');
$model->setLabel('Model');

)

Thanks,


回答1:


The easiest way is to add class to dt element, not to label:

$model->addDecorator(
    new Zend_Form_Decorator_Label(array('tag' => 'dt', 'class' => 'label-design'))
);

And then just modify your CSS selector from label.label-design to dt.label-design label




回答2:


It is possible to add a class directly to the label. Here is an awesome article from Matthew Weier O'Phinney describing all about decorators: http://devzone.zend.com/1240/decorators-with-zend_form/.

To answer your question, I would do it like this:

$model->setLabel("Model")
      ->setDecorators(array(array("Label",array("class"=>"full")),"ViewHelper"));



回答3:


Directly add the class 'label-design' to the label of your element $model:

$model->addDecorator('Label', ['class' => 'label-design']);


来源:https://stackoverflow.com/questions/3157058/zend-form-add-css-class-how-can-i-add-css-class-to-label-in-zend-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!