【发布时间】:2021-08-02 19:56:46
【问题描述】:
我在 symfony 5 和 easyadmin 3 下工作,我正在尝试创建一个表单,其中包含来自数据库的类别下拉列表,直到这里它运行良好,但是当我打开表单时,类别与他们一起显示索引而不是他们的名字......事实上我有一个使用数组的选择字段,它实际上显示内容的索引而不是他们的名字,我会告诉你
#src\Repository\CategorieRepository.php
/**
* @return Categorie[]
*/
public function findAll(){
return $this->createQueryBuilder('c')
->orderBy('c.titre', 'ASC')
->getQuery()
->getResult();
}
#src\Controller\Admin\ExerciceCrudController.php
public function getCategBdd()
{
$categ = $this->getDoctrine()
->getRepository(Categorie::class);
return $tab = array($categ->findAll());
}
public function configureFields(string $pageName): iterable
{
$tab = $this->getCategBdd();
$fields = [
ChoiceField::new('main')
->setLabel('Main')
->setChoices(['Gaucher','Droitier'])
->renderExpanded(true)
->allowMultipleChoices(true),
ChoiceField::new('categorie')
->setLabel('Categorie')
->renderAsNativeWidget(true)
->setChoices($tab),
];
return $fields;
}
我听说过用于执行此操作的实体类型,但我真的不明白我该怎么做,如果有人可以帮助我,非常感谢。
【问题讨论】:
标签: php symfony dropdown easyadmin