我试图在索引页面上显示一组单选按钮(男性或女性)。在我的表单中,我构建了这样的表单:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('gender', ChoiceType::class, array(
'choices' => array(
'Male' => 1,
'Female' => 2,
)));
}
然后在Controller中:
public function indexAction(Request $request)
{
$participantEntry = new Participants();
$form = $this->createForm(ParticipantsType::class, $participantEntry,[
'action' => $request->getUri()
]);
$form->handleRequest($request);
return $this->render('SurveyBundle:Page:index.html.twig',
['form' => $form->createView()]);
}
但是,我不确定如何在我的Twig文件中实际显示为RadioButtons,这是我尝试过的:
{% for g in form.gender %}
{{ g.value }}
{% endfor %}
顺便说一句:我的实体中的$性别是一个int
哪个不起作用,有谁知道我做错了什么?
答案 0 :(得分:-1)
将->add('gender', ChoiceType::class, array(
'choices' => array(
'Male' => 1,
'Female' => 2,
),
'expanded' => true,
'multiple' => false
);
更改为构建器,如下所示
'expanded' => true
'multiple' => false
和form_widget(form.gender)
的组合将生成单选按钮,然后在树枝中,只需使用
<telerik:RadGrid RenderMode="Lightweight" id="RadGrid1" runat="server">
<ClientSettings>
<Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" />
</ClientSettings>
</telerik:RadGrid>