I need to style each of radio button using Symfony form builder.
This is my part of my createFormBuilder
:
->add('categoryId', 'entity', array(
'class' => 'MyBundle:Category',
'property' => 'name',
'required' => false,
'expanded' => true ))
And in my twig template:
{% for child in form.categoryId %}
<div class="radio i-checks col-md-3">
<label>{{ form_widget(child, {'attr': { 'class': '', 'value': '' } }) }} </label>
</div>
{% endfor %}
How can I display name of category (now I get empty values)?
When I'm using child.get('name')
, I get this error
Method "get" for object "Symfony\Component\Form\FormView" does not exist in ...
I solved this problem by editing,
contoller:
->add('categoryId', 'entity', array( 'class' => 'MyBundle:Category', 'property' => 'name', 'expanded' => true, 'multiple' => false, 'choices' => $this->getDoctrine() ->getRepository('MyBundle:Category') ->findAll(), 'required' => true, ))
And in my twig gallery:
<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>
I hope it will help someone. greetings.