是否可以在列中显示而不是每列显示?
在FormElement
中选择了Radio选项namespace Main\Form\Element;
use Doctrine\ORM\EntityManager;
use Zend\Form\Element\Radio;
/**
* Class SurveyAnswerRadio
*
* @package Main\Form\Element
*/
class SurveyAnswerRadio extends Radio
{
/**
* @var EntityManager $entityManager
*/
protected $entityManager;
/**
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* Get Value Options
*
* @return array
*
* @throws \Exception
*/
public function getValueOptions()
{
$array = [];
$survey_question_reference = 1;
$result = $this->entityManager
->getRepository('AMDatabase\Entity\TheVerse\SA')
->findBy(
[
'sqReference' => $survey_question_reference
],
[
'surveyAnswer' => 'ASC'
]
);
if (is_array($result) && count($result) > '0') {
/**
* @var \AMDatabase\Entity\TheVerse\SA $val
*/
foreach ($result as $val) {
$array[$val->getReference()] = $val->getSurveyAnswer();
}
}
return $array;
}
}
这已添加到表单
/**
* Survey Answer
*/
$this->add(
[
'type' => 'Main\Form\Element\SurveyAnswerRadio',
'name' => 'survey_answer',
'options' => [
'label' => 'survey_answer'
],
'attributes' => [
'id' => 'survey_answer'
]
]
);
}
然后它显示在视图Twig
中<div class="field">
<span>{{ formLabel(form.get('survey_answer')) }}</span>
{{ formRadio(form.get('survey_answer')) }}
</div>
输出将每个包含在a中。我希望输出以这种方式显示:
<ul>
<li><label><input type="radio" name="survey_answer" id="survey_answer" value="1">option 1</label><li>
<li><label><input type="radio" name="survey_answer" id="survey_answer" value="2">option 2</label></li>
<li><label><input type="radio" name="survey_answer" id="survey_answer" value="3">option 3</label></li>
</ul>
答案 0 :(得分:1)
在视图中使用此命令
$this->formRadio()->setSeparator('</li><li class="yourclass">');
此命令在您的电台选项之间设置分隔符。
然后你会像这样显示你的元素
<li class="yourclass" >
<?php echo $this->formRadio($form->get('survey_answer')); ?>
</li>