Created
February 22, 2012 21:50
-
-
Save raulfraile/1887653 to your computer and use it in GitHub Desktop.
Colecciones en formularios de Symfony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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