ZF2 收音机输入栏显示

ZF2 Radio Input Display in Column

是否可以在一列中而不是并排显示?

在 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>

输出将每个都包含在一个 .我希望以这种方式显示输出:

<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>

在视图中使用此命令

$this->formRadio()->setSeparator('</li><li class="yourclass">');

此命令设置单选选项之间的分隔符。

然后你像这样显示你的元素

<li class="yourclass" >
 <?php echo $this->formRadio($form->get('survey_answer')); ?>
</li>