添加 Symfony EasyAdmin 3.x ManyToMany 错误:The Doctrine type of the .... 字段为“4”,EasyAdmin 尚不支持

jer*_*her 5 symfony easyadmin

我正在尝试使用 easyAdmin 3.x 在两个类之间建立一个简单的 ManyToMany 关系,当我尝试显示实体 CRUD 时,我经常出现此错误:

“salles”字段的Doctrine类型为“4”,EasyAdmin尚不支持。

这两个实体都存在函数 __to string

public function __toString()
    {
        return $this->name;
    }
Run Code Online (Sandbox Code Playgroud)

我的 CrudController:

namespace App\Controller\Admin;

use App\Entity\Batiment;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;


class BatimentCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Batiment::class;
    }


    public function configureFields(string $pageName): iterable
    {
        return [
            'name',
            'salles'

        ];
    }

}
Run Code Online (Sandbox Code Playgroud)

easyadmin 3.x 不管理多对多关系吗?

有没有一种特殊的方式来管理和显示这些关系?

我发现了这个捆绑包,感谢您的帮助!

Rad*_*mir 6

在 EasyAdmin 3.x 中,为所有关联映射添加了新的专用类型。

请使用类似的东西:

namespace App\Controller\Admin;
    
use App\Entity\Batiment;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
        
        
class BatimentCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Batiment::class;
    }

    public function configureFields(string $pageName): iterable
    {
        return [
            Field::new('id')->hideOnForm(),
            Field::new('name'),
            Field::new('Letter'),
            ImageField::new('image'),
            AssociationField::new('products')
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)

  • `AssociationField::new('...')` 对我有用。谢谢 ;-) (2认同)

jer*_*her 0

这是我的 Batiment 实体类的定义

    <?php

namespace App\Entity;

use App\Repository\BatimentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=BatimentRepository::class)
 */
class Batiment
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

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

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

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

    /**
     * @ORM\OneToMany(targetEntity=Salle::class, mappedBy="batiment")
     */
    private $salles;

    public function __construct()
    {
        $this->salles = new ArrayCollection();
    }

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

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getLetter(): ?string
    {
        return $this->Letter;
    }

    public function setLetter(?string $Letter): self
    {
        $this->Letter = $Letter;

        return $this;
    }

    public function getImage(): ?string
    {
        return $this->image;
    }

    public function setImage(?string $image): self
    {
        $this->image = $image;

        return $this;
    }

    /**
     * @return Collection|Salle[]
     */
    public function getSalles(): Collection
    {
        return $this->salles;
    }

    public function addSalle(Salle $salle): self
    {
        if (!$this->salles->contains($salle)) {
            $this->salles[] = $salle;
            $salle->setBatiment($this);
        }

        return $this;
    }

    public function removeSalle(Salle $salle): self
    {
        if ($this->salles->contains($salle)) {
            $this->salles->removeElement($salle);
            // set the owning side to null (unless already changed)
            if ($salle->getBatiment() === $this) {
                $salle->setBatiment(null);
            }
        }

        return $this;
    }

    public function __toString()
    {
        return $this->name;
    }
}
Run Code Online (Sandbox Code Playgroud)