Skip to content

Instantly share code, notes, and snippets.

@raulfraile
Created February 22, 2012 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raulfraile/1887653 to your computer and use it in GitHub Desktop.
Save raulfraile/1887653 to your computer and use it in GitHub Desktop.
Colecciones en formularios de Symfony
/* Form hijo */
<?php
namespace Acme\Bundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class HijoType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name');
}
public function getName()
{
return 'hijo';
}
}
/* Form padre */
<?php
namespace Acme\Bundle\Form\Admin;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Acme\Bundle\Form\HijoType;
class PadreType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('hijos', 'collection', array(
'type' => new HijoType()
));
}
public function getName()
{
return 'padre';
}
}
/* Template */
...
{% for item in form.hijos %}
{{ form_row(item.name) }}
{% endfor %}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment