Symfony2,在Sonata Admin上更改其他列表时填写选项表单

时间:2014-01-16 00:59:27

标签: symfony sonata-admin

我在Sonata Admin中有一个带有几个下拉列表的表单,每个下拉列表应该使用另一个服务(实体)的值填充下一个表单,这可能吗?

1 个答案:

答案 0 :(得分:0)

 protected function configureFormFields(FormMapper $formMapper)
 {

    $em = $this->modelManager->getEntityManager('YourBundleFile\YourBundleFileBundle\Entity\YourEntity');

    $qb = $em->createQueryBuilder();

    $qb = $qb->add('select', 'u')
            ->add('from', 'YourBundleFile\YourBundleFileBundle\Entity\YourEntity u');

    $query = $qb->getQuery();
    $arrayType = $query->getArrayResult();

$formMapper
->add('yourProperty', 'choice', array('choices'=>$arrayType))
-end();
}