symfony - 如何在 Symfony 中使用'choice_name'?
问题描述
我有一个带有西里尔字母名称的复选框列表。它生成
<input type="checkbox" id="region_form_name_22" name="region_form[name][]" value="22">"
我想输入$query = $request->query->get("region_form");
一个字符串值(如“Алтайская область”。
我尝试使用“choice_name” ,但出现错误
"The name "Алтайский край" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":")."
$builder->add('name', EntityType::class, [
'class' => Region::class,
'choice_label' => 'name_with_type',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.name_with_type', 'ASC');
},
'choice_name' => function ($entity) {
return $entity->getNameWithType();
},
'multiple' => true,
'expanded' => true,
])
->add('save', SubmitType::class, array('label' => 'Найти'))
;
如何在查询中获取不是“id”,而是“name”?
解决方案
推荐阅读
- python - 如何在 python 中使用 keras 训练具有列表数组的神经网络
- linux - Spring Security getprincipal() 方法返回字符串(用户名)代替类 UserDetails
- python-3.x - 如何将多行字典转换为单个格式化字典?- Python
- java - 读取字符串后将 int 位置设置为行
- triggers - Azure 数据工厂 ADFV2 触发器重叠
- c# - CustomHost 导致 T4 模板转换出错
- c++ - 如何使用 protoc 的 decode 选项对 google::protobuf:any 类型进行解码
- python - 如何将 cov 函数用于数据集 iris python
- r - 您可以使用 lapply/sapply on 将一个列表的元素应用到另一个列表的相应元素吗?
- c - 用strcmp比较两个字符串时word[0]是什么意思