2015-06-14 98 views
1

我需要使用Symfony表单构建器对每个单选按钮进行样式设置。Symfony/Twig无线电风格formbuilder

这是我的我的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 \分量\表格\ FormView控件” 中不存在...

回答

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>

我希望这会帮助别人。问候。

0

我猜

child.name 

(而无需输入至少30个字符,我不能张贴此答案)

+0

我被试过了,但是我的对象“Symfony \ Component \ Form \ FormView”出现错误'Method“name”MyBundle :: add.html.twig'中不存在 – Gemmi