add a virtual property in easy-admin bundle

删除回忆录丶 提交于 2019-12-25 00:22:18

问题


I'm currently working with the 2.3 version of the easy-admin bundle in Symfony 4.

I try to create a virtual property for the new view. I have the following configuration

#config/packages/easy_admin.yaml
easy_admin:
    entities:
        Field:
            class: App\Entity\Field
            form: 
                fields: 
                    - { type: tab, label: initial information, icon: pencil-alt }
                    - name
            new:
                fields:
                    - { property: toto, type: file }

and my entity file:

//src/Entity/Field.php

/**
 * @ORM\Entity(repositoryClass="App\Repository\FieldRepository")
 */
class Field
{
    public function setToto(?File $file): self
    {
        $this->setImage(new Image);
        $this->getImage()->setImageFile($file);
    }

as explain in the documentation the setter should be sufficient.

but when I reach the new page I get the following error:

Neither the property "toto" nor one of the methods "getToto()", "toto()", "isToto()", "hasToto()", "__get()" exist and have public access in class "App\Entity\Field".

which means that the page is looking for getter and not setter. Is it normal or did I make something wrong ?


回答1:


I have just ran into this issue and I have solved it by adding the getter. As you said, it is looking for getter but also setter.



来源:https://stackoverflow.com/questions/58649435/add-a-virtual-property-in-easy-admin-bundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!