您好我正在使用zend我想在特定标签中添加一些样式我怎么能
class Application_Form_CategoryEnablingItemsForm extends Zend_Form {
public $elementDecorators = array(
'ViewHelper',
'Errors',
array('Description', array('tag' => 'p', 'class' => 'description')),
array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'col-md-4 displaycls')),
array('Label', array('class' => 'col-md-3 control-label displaylbl', 'requiredSuffix' => '*')),
array('Errors', array('class' => 'zend-error'))
);
$this->addElement('select', 'product_category_parent', array(
'label' => 'Product Category Parent Name',
'required' => true,
'multiOptions' => $productCategory_options,
'filters' => array('StringTrim'),
'class' => 'form-control selection parent_category',
));
$productCategory_sub = $productCategoryMapper->getAllProductCategory();
$productCategory_sub_options = array();
$productCategory_sub_options[""]= "-Product Sub Category Name-";
if($productCategory_sub)
{
foreach ($productCategory_sub as $category)
{
$productCategory_sub_options[$category->product_category_id] = $category->product_category_name;
}
}
我添加了'attribs' => array ('style' => 'margin-left: -799px; ')
但它适用于整个选择选项不适用于标签,任何建议?
答案 0 :(得分:3)
尝试下面的代码,只需添加你的lable样式类来代替my-class-name类。
$element = $this->createElement("select", 'product_category_parent');
$element->setLabel('Product Category Parent Name');
$element->setRequired(TRUE);
$element->addMultiOptions($productCategory_options);
$element->setAttrib("class", 'form-control selection parent_category');
$element->removeDecorator('HtmlTag');
$element->setDecorators(array('ViewHelper'));
$element->getDecorator('Label')->setOption('class', 'my-class-name');