我有简单的Radio元素:
$form->add([
'name' => 'account_type',
'type' => 'Zend\Form\Element\Radio',
'options' => [
'label' => 'Account type',
'value_options' => [
1 => 'Employer',
2 => 'Performer'
]
]
]
);
但在我看来,我得到了这个HTML:
<div class="zf-form-el-account_type">
<label for="account_type">Account type</label>
<div class="zf-radio">
<label>
<input type="radio" name="account_type" class="account_type" value="1">Employer
</label>
</div>
<div class="zf-radio">
<label>
<input type="radio" name="account_type" class="account_type" value="2">Performer
</label>
</div>
</div>
如何在无线电元素周围删除这个空标签包装?或者我如何在无线电元素后插入一些标签?感谢。
答案 0 :(得分:1)
我扩展了标准视图助手:
<?php
namespace Application\Form\View\Helper;
use Zend\Form\View\Helper\FormRadio;
use Zend\Form\Element\Radio as RadioEl;
class FormRadioElement extends FormRadio
{
protected function renderOptions(RadioEl $element, array $options, array $selectedOptions, array $attributes)
{ ...
...并在帮助器中设置模板,如:
$template = '%s%s';
然后我在我的引导程序中声明了它:
public function getViewHelperConfig() {
return [
'invokables' => [
'formRadioHelper' => 'Application\Form\View\Helper\FormRadioElement',
]
];
}
......在我的观点中称为:
<?php echo $this->formRadioHelper($form->get('account_type'))?>