我正在使用 symfony 2.3.2,我正在尝试通过这种方式在我的表单类型上将子元素添加到集合中
<?php
namespace candgo\EventoBundle\Form\Ajax;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use candgo\EventoBundle\Entity\Entrada;
use candgo\EventoBundle\Form\EntradaOrderType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class EntradaAjaxType extends AbstractType
{
protected $em,$id_evento;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('abc','collection');
$builder->get('abc')->add('poc');
}
public function __construct($em,$id_evento)
{
$this->em=$em;
$this->id_evento=$id_evento;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'show_legend' => false,
));
}
public function getName()
{
return 'purchase_tickets2';
}
}
我还尝试了 symfony doc 提供的代码示例
$builder->add('favorite_cities', 'collection', array(
'type' => 'choice',
'options' => array(
'choices' => array(
'nashville' => 'Nashville',
'paris' => 'Paris',
'berlin' => 'Berlin',
'london' => 'London',
),
),
));
在两次追逐中,呈现的表格都是空的,有人知道会是问题吗?