首页 文章

Symfony / Twig无线电风格formbuilder

提问于
浏览
1

我需要使用Symfony表单构建器设置每个单选按钮的样式 .

这是我的 createFormBuilder 的一部分:

->add('categoryId', 'entity', array(
                'class' => 'MyBundle:Category',
                'property' => 'name',
                'required' => false,
                'expanded' => true ))

在我的树枝模板中:

{% for child in form.categoryId %}
    <div class="radio i-checks col-md-3">
        <label>{{ form_widget(child, {'attr': { 'class': '', 'value': '' } }) }} </label>
    </div>
{% endfor %}

如何显示类别名称(现在我得到空值)?

当我使用 child.get('name') 时,我收到此错误

方法“获取”对象“Symfony \ Component \ Form \ FormView”在...中不存在

2 回答

  • 0

    我猜

    child.name
    

    (我无法在不输入至少30个字符的情况下发布此答案)

  • 0

    我通过编辑解决了这个问题,

    位指示:

    ->add('categoryId', 'entity', array( 'class' => 'MyBundle:Category', 'property' => 'name', 'expanded' => true, 'multiple' => false, 'choices' => $this->getDoctrine() ->getRepository('MyBundle:Category') ->findAll(), 'required' => true, ))

    在我的枝条画廊:

    <div class="row"> {% for child in form.categoryId %} <div class="radio i-checks col-md-3"> <label>{{ form_widget(child, {'attr': { 'class': 'required', 'value': child.vars.value } }) }} {{ child.vars.label }} </label> </div> {% endfor %} </div>

    我希望它能帮助别人 . 问候 .

相关问题