Select 个框与另一个 select 个框相关

Select box related on another select box

我有一个实体 Travel 有一个属性 country 我有一个实体 City与旅行有关。 当我选择一个显示所有相关城市的国家/地区时,我希望如此。事实上我不知道 Ajax 我需要帮助

class TravelType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
      $builder
        ->add('country', 'country', array(
         'required' => true,
         'label' => 'Country',
         ))
        ->add('destination', 'entity',array(
         'required' => true,
         'class' => 'ProjectAdminBundle:City',
         'property' => 'name',
         'multiple' => false,
         'expanded' => false,
         'empty_value' => 'Choose a city',
         'label' => 'Destination',
         ))
         //.....
    }
}

这是实体旅行:

class Travel
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

 /**
 * @ORM\Column(name="country", type="string", length=255, nullable=false)
 *
 * @Assert\Country
 */
protected $country;

/**
 * @ORM\ManyToOne(targetEntity="Project\AdminBundle\Entity\City", inversedBy="travels")
 * @ORM\JoinColumn(nullable=false)
 */
protected $destination;
//........

}

每个城市都有一个国家代码,例如:

伦敦 -> 英国

巴黎 -> 法国 .....

Symphony Cookbook 中详细讨论了与您类似的案例:

http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html#dynamic-generation-for-submitted-forms