我在Sonata Admin中有一个带有几个下拉列表的表单,每个下拉列表应该使用另一个服务(实体)的值填充下一个表单,这可能吗?
答案 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();
}