【发布时间】:2020-02-22 19:59:41
【问题描述】:
我使用的是easyAdminBundle,我想知道是否可以使用static function 或const(在我的应用程序中定义)来设置choice 类型的choices 选项:
- { property: tag, type: choice, type_options: { choices: 'App\Entity\News::getTags' }
使用getTags 函数,例如:
class News
{
const TAGS = ['toto','tutu'];
static public function getTags()
{
return $this::TAGS;
}
}
query_builder 已经可以做到这一点,但我在文档中没有找到任何痕迹。
实际上我收到以下错误,导致我认为这是不可能的(但也许这里有人这样做):
解析“Symfony\Component\Form\Extension\Core\Type\ChoiceType”形式的选项时发生错误:值“App\Entity\News::getTags”的选项“choices”应为类型为“null”或“array”或“\Traversable”,但类型为“string”。
【问题讨论】: