问题描述
我有 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 (将#修改为@)