3

我正在使用带有 symfony4 的 easy-admin 的 vich-uploader 捆绑包。设置后,我在尝试删除或更新实体时收到此错误

属性路径“imageName”中给出的“字符串”类型的预期参数,“NULL”。

对于这种常见情况,应用程序的配置是最容易的。矿山测试实体:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;


/**
 * @ORM\Entity(repositoryClass="App\Repository\TestRepository")
 * @Vich\Uploadable
 */
class Test
{
/**
 * @ORM\Id()
 * @ORM\GeneratedValue()
 * @ORM\Column(type="integer")
 */
private $id;

/**
 * @ORM\Column(type="string", length=255)
 */
private $imageName;

/**
 * @Vich\UploadableField(mapping="test_images", fileNameProperty="imageName")
 * @var File
 */
private $imageFile;

/**
 * @ORM\Column(type="datetime")
 * @var \DateTime
 */
private $updatedAt;


public function getId()
{
    return $this->id;
}

public function getImageName()
{
    return $this->imageName;
}

public function setImageName(string $image)
{
    $this->imageName = $image;

    return $this;
}

public function setImageFile(File $image = null)
{
    $this->imageFile = $image;

    if ($image) {
        $this->updatedAt = new \DateTime('now');
    }
}

public function getImageFile()
{
    return $this->imageFile;
}


public function getUpdatedAt()
{
    return $this->updatedAt;
}

public function setUpdatedAt(\DateTime $datetime)
{
    $this->updatedAt = $datetime;

    return $this;
}
}

我的简单管理 yaml 配置

easy_admin:
    entities:
        Test:
            class: App\Entity\Test
            form:
                fields:
                    - { property: 'imageFile', type: 'vich_image' }
            # ...
            list:
                fields:
                    - { property: 'image', type: 'image', base_path: '%app.path.banner_images%' }
            # ...
            show:
                fields:
                    - { property: 'image', type: 'image', base_path: '%app.path.banner_images%' }
4

1 回答 1

9

尝试

public function setImageName(?string $image)
{
    $this->imageName = $image;

    return $this;
}
于 2018-12-19T09:05:46.487 回答