您好,我正在尝试查看(从得出结论后)如何验证其中之一'choices' => $question->buildAnswerWithValidKey()是正确的。
这是问题数组。
Array
(
[Sonne] => 1
[Mond] =>
[Und Sterne] =>
)
我试图在表格被提出后对此进行验证。
这是我的'choices'功能。根据具有正确密钥的问题(在这种情况下为1或0,是/否),它会得到答案。
public function buildAnswerWithValidKey()
{
$answers = [];
$valid = [];
$answersWithValidKey = [];
/** @var Answer $answer */
foreach ($this->getAnswers() as $answer) {
$answers[] = $answer->getAnswer();
$valid[] = $answer->getValid();
}
//Sets answers as item and valid as key as required by 'choices'
$answersWithValidKey[] = array_combine($answers, $valid);
return $answersWithValidKey;
}
这是我的控制器。我在努力验证单选按钮的位置。
/** @var Question $question */
$question = $this->questionRepository->findById(12)[0];
$options = ['question' => $question];
$form = $this->createForm(ExamType::class, null, $options);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
}
return [
'form' => $form->createView(),
];
这是我可能有帮助的其他课程。
Answer.php-ManyToOne映射到的位置。
料青山看我应如是