我正在尝试为一组单选按钮中的每个标签添加一个类(相同).
这是我的代码:
$linkedin_share = new Zend_Form_Element_Radio('linkedin_share',array('escape' => false)); $linkedin_share->setDecorators(array('ViewHelper','Errors',array('Label',array('class' => 'TEST')))) ->addMultiOption('none',$this->getView()->translate('None')) ->addMultiOption('icon','<img src="'.$this->getView()->baseUrl().'/images/admin/icons/social_media_share/linkedin.png'.'"/>') ->addMultiOption('counter','<img src="'.$this->getView()->baseUrl().'/images/admin/icons/social_media_share/linkedin_share.jpg'.'"/>') ->setSeparator('') ->setAttrib('class','item_small_checkBox');
这是我的输出:
<label for="linkedin_share-none"> <label for="linkedin_share-icon"> <label for="linkedin_share-counter">
这是我想要的输出:
<label for="linkedin_share-none" class="share_label_class"> <label for="linkedin_share-icon" class="share_label_class"> <label for="linkedin_share-counter" class="share_label_class">
愚蠢的是它到目前为止适用于我所有其他表单元素.我尝试了一百万种组合并搜索了我的屁股,但无论我尝试什么,我都无法在标签上添加类.
想法,解决方案,建议都非常欢迎!提前致谢!
我花了两个小时才找到答案,这真是太简单了!将此行添加到您的声明中: –
原文链接:https://www.f2er.com/php/133764.html->setAttrib('label_class','share_label_class')
Zend / View / Helper / FormRadio.PHP第79-95行给了我线索.
$label_attribs = array(); foreach ($attribs as $key => $val) { $tmp = false; $keyLen = strlen($key); if ((6 < $keyLen) && (substr($key,6) == 'label_')) { $tmp = substr($key,6); } elseif ((5 < $keyLen) && (substr($key,5) == 'label')) { $tmp = substr($key,5); } if ($tmp) { // make sure first char is lowercase $tmp[0] = strtolower($tmp[0]); $label_attribs[$tmp] = $val; unset($attribs[$key]); } }
这适用于我的系统,我希望它也适合你.