在 symfony2 的下拉列表中隐藏特定选项
Hide specific options in dropdown in symfony2
我有一个包含这三个字段的表单。所以在 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'))
;
}
查询生成器可以为您完成此操作,您已经尝试了吗?
use Doctrine\ORM\EntityRepository;
->add('catalogLevelId', 'entity',
array (
...,
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->orderBy('c.name', 'ASC');
}))
我有一个包含这三个字段的表单。所以在 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'))
;
}
查询生成器可以为您完成此操作,您已经尝试了吗?
use Doctrine\ORM\EntityRepository;
->add('catalogLevelId', 'entity',
array (
...,
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->orderBy('c.name', 'ASC');
}))