微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

EasyAdmin 3 中一个 CrudController 中的 2 个实体的字段

如何解决EasyAdmin 3 中一个 CrudController 中的 2 个实体的字段

我正在做一个个人项目,但遇到了一个小问题。

我有 2 个实体,Bibliotheque 和 ComicBook。我希望这两个实体的字段存在于单个 CrudController 中,我将其命名为 BibliothequeCrudController。

我实现了 createIndexQueryBuilder 函数修改我的列表的结果。

public function createIndexQueryBuilder(SearchDto $searchDto,EntityDto $entityDto,FieldCollection $fields,FilterCollection $filters): QueryBuilder
    {

        $em = $this->getDoctrine()->getManager();
        $qb = $em->createqueryBuilder();
        $qb->select(array('b'));
        $qb->from('App\Entity\Bibliotheque','b');
        $qb->innerJoin('b.comic_book','c');
        $qb->addSelect('c');
        // $qb->Where("b.user = ".$this->security->getUser()->getId());
        // dd($qb->getQuery()->getResult());
        return $qb;
    }

功能运行良好。如果我使用:

dd($qb->getQuery()->getResult());

我得到了信息:

BibliothequeCrudController.PHP on line 73:
array:1 [▼
  0 => App\Entity\Bibliotheque {#1145 ▼
    -id: 64
    -comic_book: Doctrine\ORM\PersistentCollection {#1149 ▼
      -snapshot: array:1 [ …1]
      -owner: App\Entity\Bibliotheque {#1145}
      -association: array:20 [ …20]
      -em: Doctrine\ORM\EntityManager {#704 …11}
      -backRefFieldName: "bibliothequesComicBook"
      -typeClass: Doctrine\ORM\Mapping\ClassMetadata {#1083 …}
      -isDirty: false
      #collection: Doctrine\Common\Collections\ArrayCollection {#1148 ▼
        -elements: array:1 [▼
          0 => App\Entity\ComicBook {#1143 ▼
            -id: 4
            -titre: Proxies\__CG__\App\Entity\Serie {#1194 ▶}
            -sous_titre: "(Must Have)"
            -date_creation: DateTime @1593561600 {#1147 ▶}
            -isbn: null
            -nb_page: 200
            -resume: null
            -image: "609b8fcbea932677061888.jpg"
            -imageFile: null
            -genre: Doctrine\ORM\PersistentCollection {#1203 ▶}
            -edition: Doctrine\ORM\PersistentCollection {#1229 ▶}
            -publication: Doctrine\ORM\PersistentCollection {#1251 ▶}
            -scenario: Doctrine\ORM\PersistentCollection {#1283 ▶}
            -dessin: Doctrine\ORM\PersistentCollection {#1315 ▶}
            -couleur: Doctrine\ORM\PersistentCollection {#1347 ▶}
            -numero: null
            -bibliothequesComicBook: Doctrine\ORM\PersistentCollection {#1350 ▶}
            -episode: null
          }
        ]
      }
      #initialized: true
    }
    -user: App\Entity\User {#855 ▶}
  }
]

但我似乎无法获取字段中的信息。 我试过:

TextField::new('ComicBook.sous_titre'),

还有其他方式,但我卡住了。

我提供了 2 个实体:

// App\Entity\Bibliotheque.PHP

class Bibliotheque
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\ManyToMany(targetEntity=ComicBook::class,inversedBy="bibliothequesComicBook")
     */
    private $comic_book;

    /**
     * @ORM\ManyToOne(targetEntity=User::class,inversedBy="bibliothequeUser")
     */
    private $user;
// App\Entity\ComicBook.PHP

class ComicBook
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity=Serie::class,inversedBy="serieComics")
     * @ORM\JoinColumn(nullable=false)
     */
    private $titre;

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

    /**
     * @ORM\Column(type="date",nullable=true)
     */
    private $date_creation;

    /**
     * @ORM\Column(type="bigint",nullable=true)
     */
    private $isbn;

    /**
     * @ORM\Column(type="integer",nullable=true)
     */
    private $nb_page;

    /**
     * @ORM\Column(type="text",nullable=true)
     */
    private $resume;

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

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

    /**
     * @ORM\ManyToMany(targetEntity=Genre::class,inversedBy="genreComics")
     */
    private $genre;

    /**
     * @ORM\ManyToMany(targetEntity=Edition::class,inversedBy="editionComics")
     */
    private $edition;

    /**
     * @ORM\ManyToMany(targetEntity=Publication::class,inversedBy="publicationComics")
     */
    private $publication;

    /**
     * @ORM\ManyToMany(targetEntity=Scenariste::class,inversedBy="scenarioComics")
     */
    private $scenario;

    /**
     * @ORM\ManyToMany(targetEntity=Dessinateur::class,inversedBy="dessinComics")
     */
    private $dessin;

    /**
     * @ORM\ManyToMany(targetEntity=Coloriste::class,inversedBy="couleurComics")
     */
    private $couleur;

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

    /**
     * @ORM\ManyToMany(targetEntity=Bibliotheque::class,mappedBy="comic_book")
     */
    private $bibliothequesComicBook;

    /**
     * @ORM\Column(type="array",nullable=true)
     */
    private $episode = [];

如果您需要更多信息,请询问我。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。