隐藏symfony2下拉列表中的特定选项

时间:2015-03-17 08:47:11

标签: php forms symfony

我有一个包含这三个字段的表单。所以在catalogLevelId中,我不需要下拉列表中的所有数据,只需要一些。怎么做?

 public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('title')
            ->add('parent', 'entity', array('class' => 'RetailMappingCatalogBundle:Catalog', 'property' => 'title'))
            ->add('catalogLevelId', 'entity', array('class' => 'RetailMappingCatalogBundle:CatalogLevel', 'property' => 'name'))
            ->add('save', 'submit', array('label' => 'Submit'))
        ;
    }

1 个答案:

答案 0 :(得分:1)

查询构建器可以为您执行此操作,您是否已尝试过?

use Doctrine\ORM\EntityRepository;

       ->add('catalogLevelId', 'entity',
                            array (
                                    ...,
                                    'query_builder' => function(EntityRepository $er) {
                                            return $er->createQueryBuilder('c')
                                                ->orderBy('c.name', 'ASC');
                                        }))
相关问题