php - Symfony2.8:choices_as_values 不起作用
问题描述
Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList
并Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList
已在 Symfony2.8 中重写(详细信息在下面的帖子中)。
之后Symfony3出现验证错误,表单中选择的作者保存失败。
我将其归因于选择类型键和值的交换。
所以,在提出 Symfony 之前,我指定chouces_as_values
为 Type 并验证它是否有效。
但它没有用,结果是相似的。换句话说,我们能不能认为这不是关键值的替换?
可能是ChoiceList的重写失败了。另外,我想就在哪里进行调试提供建议,以便您了解原因。
Symfony:无法反转属性路径的值 [...]:选择 [...] 不存在或不唯一
https://symfony.com/doc/2.8/reference/forms/types/choice.html#choices-as-values
ArticleType
$ChoiceList = new StaffChoiceLoader($this->staffService, $options['login_staff']);
//$ChoiceList = new StaffChoiceList($this->staffService, $options['login_staff']);
$builder->add("author", "entity", array(
"required" => true,
"class" => "AppBundle:Staff",
"choice_loader" => $ChoiceList,
//"choice_list" => $ChoiceList,
"empty_value" => "Please select",
//Add
"choices_as_values" => true,
));
文章实体
/**
* author
*
* @ORM\ManyToOne(targetEntity="Staff")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=true)
*/
protected $author;
解决方案
推荐阅读
- java - 在 PoolProperties 类中添加编码
- python - tf.data.Dataset.map() 的输出张量形状有些奇怪
- json - 如何使用 SQFLite 或 Moor 库将 JSON 数据存储到颤振中的数据库表中
- r - 从 R 连接到麒麟
- java - Java Mockito-如何模拟参数方法的不确定数量
- java - 使用 spring 集成测试 MultipartFile 上传
- java - 使用 When vs Verify 验证方法调用
- c# - 取消时间或手动取消的 CancellationToken。嵌套取消令牌
- node.js - 在 mongo 聚合中使用当前文档键
- .net - 客户端有时会在启用 Kerberos 后协商 NTLM,直到客户端服务器重新启动。如何避免重启?