在easy-admin bundle中添加一个虚拟属性 [英] add a virtual property in easy-admin bundle

查看:24
本文介绍了在easy-admin bundle中添加一个虚拟属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 Symfony 4 中使用 2.3 版本的 easy-admin 包.

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 }

和我的实体文件:

//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);
    }

文档中的解释 setter 应该足够了.

但是当我到达 new 页面时,我收到以下错误:

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

属性toto"和方法getToto()"、toto()"、isToto()"、hasToto()"、__get()"都不存在并且在类中具有公共访问权限应用\实体\字段".

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

这意味着页面正在寻找 getter 而不是 setter.这是正常的还是我做错了什么?

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

推荐答案

我刚刚遇到了这个问题,我通过添加 getter 解决了它.正如您所说,它正在寻找 gettersetter.

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.

这篇关于在easy-admin bundle中添加一个虚拟属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆