首页 > 解决方案 > Symfony2.8:choices_as_values 不起作用

问题描述

Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListSymfony\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;

标签: phpsymfony

解决方案


推荐阅读