- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
getRepository(Item::cl-6ren">
我的实体 Item
有一个存储库 (ItemRepository
),函数为 findItemCount()
。当我使用
$repository = $em->getRepository(Item::class);
$items = $repository->findItemCount();
我收到警告:
Potentially polymorphic call. The code may be inoperable depending on the actual class instance passed as the argument.
此外,自动完成功能不建议我使用函数“findItemCount”。我的错误是什么?
Controller :
/**
* Artikel Liste
* @Route("/item/list", name="app_item_list")
* @param EntityManagerInterface $em
* @return Response
*/
public function listItems(EntityManagerInterface $em): Response
{
$repository = $em->getRepository(Item::class);
$items = $repository->findItemCount();
return $this->render('item_admin/itemList.html.twig', [
'items' => $items,
'title' => 'Artikel Übersicht',
'blocked' => false
]);
}
项目.php
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OrderBy;
/**
* @ORM\Entity(repositoryClass="App\Repository\ItemRepository")
*/
class Item
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @OrderBy({"name" = "ASC"})
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Itemparent", inversedBy="item")
*/
private $itemparent;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Itemgroup", inversedBy="items")
*/
private $itemgroup;
/**
* @ORM\Column(type="string", length=255)
*/
private $minsize;
/**
* @ORM\Column(type="boolean")
*/
private $charge;
/**
* @ORM\Column(type="boolean")
*/
private $blocked;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Barcode", mappedBy="item", orphanRemoval=true)
*/
private $barcodes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ItemStock", mappedBy="item", orphanRemoval=true)
*/
private $itemStocks;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BookingItem", mappedBy="item", orphanRemoval=true)
*/
private $bookingItems;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $price;
/**
* @ORM\OneToMany(targetEntity=SupplierItems::class, mappedBy="item")
*/
private $supplierItems;
/**
* @ORM\OneToMany(targetEntity=ItemStockCharge::class, mappedBy="item")
*/
private $itemStockCharges;
public function __construct()
{
$this->barcodes = new ArrayCollection();
$this->itemStocks = new ArrayCollection();
$this->suppliers = new ArrayCollection();
$this->supplierItems = new ArrayCollection();
$this->itemStockCharges = 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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getItemparent(): ?Itemparent
{
return $this->itemparent;
}
public function setItemparent(?Itemparent $itemparent): self
{
$this->itemparent = $itemparent;
return $this;
}
public function getItemgroup(): ?Itemgroup
{
return $this->itemgroup;
}
public function setItemgroup(?Itemgroup $itemgroup): self
{
$this->itemgroup = $itemgroup;
return $this;
}
public function getMinsize(): ?string
{
return $this->minsize;
}
public function setMinsize(string $minsize): self
{
$this->minsize = $minsize;
return $this;
}
public function getCharge(): ?bool
{
return $this->charge;
}
public function setCharge(bool $charge): self
{
$this->charge = $charge;
return $this;
}
public function getBlocked(): ?bool
{
return $this->blocked;
}
public function setBlocked(bool $blocked): self
{
$this->blocked = $blocked;
return $this;
}
/**
* @return Collection|Barcode[]
*/
public function getBarcodes(): Collection
{
return $this->barcodes;
}
public function addBarcode(Barcode $barcode): self
{
if (!$this->barcodes->contains($barcode)) {
$this->barcodes[] = $barcode;
$barcode->setItem($this);
}
return $this;
}
public function removeBarcode(Barcode $barcode): self
{
if ($this->barcodes->contains($barcode)) {
$this->barcodes->removeElement($barcode);
// set the owning side to null (unless already changed)
if ($barcode->getItem() === $this) {
$barcode->setItem(null);
}
}
return $this;
}
/**
* @return Collection|ItemStock[]
*/
public function getItemStocks(): Collection
{
return $this->itemStocks;
}
public function addItemStock(ItemStock $itemStock): self
{
if (!$this->itemStocks->contains($itemStock)) {
$this->itemStocks[] = $itemStock;
$itemStock->setItem($this);
}
return $this;
}
public function removeItemStock(ItemStock $itemStock): self
{
if ($this->itemStocks->contains($itemStock)) {
$this->itemStocks->removeElement($itemStock);
// set the owning side to null (unless already changed)
if ($itemStock->getItem() === $this) {
$itemStock->setItem(null);
}
}
return $this;
}
/**
* @return Collection|BookingItem[]
*/
public function getBookingItems(): Collection
{
return $this->bookingItems;
}
public function addBookingItem(BookingItem $bookingItem): self
{
if (!$this->bookingItems->contains($bookingItem)) {
$this->bookingItems[] = $bookingItem;
$bookingItem->setItem($this);
}
return $this;
}
public function removeBookingItem(BookingItem $bookingItem): self
{
if ($this->bookingItems->contains($bookingItem)) {
$this->bookingItems->removeElement($bookingItem);
if ($bookingItem->getItem() === $this) {
$bookingItem->setItem(null);
}
}
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = $price;
return $this;
}
public function getCommaPrice(): string
{
return number_format($this->price, 2, ',', '');
}
/**
* @return Collection|SupplierItems[]
*/
public function getSupplierItems(): Collection
{
return $this->supplierItems;
}
public function addSupplierItem(SupplierItems $supplierItem): self
{
if (!$this->supplierItems->contains($supplierItem)) {
$this->supplierItems[] = $supplierItem;
$supplierItem->setItem($this);
}
return $this;
}
public function removeSupplierItem(SupplierItems $supplierItem): self
{
if ($this->supplierItems->contains($supplierItem)) {
$this->supplierItems->removeElement($supplierItem);
// set the owning side to null (unless already changed)
if ($supplierItem->getItem() === $this) {
$supplierItem->setItem(null);
}
}
return $this;
}
/**
* @return Collection|ItemStockCharge[]
*/
public function getItemStockCharges(): Collection
{
return $this->itemStockCharges;
}
public function addItemStockCharge(ItemStockCharge $itemStockCharge): self
{
if (!$this->itemStockCharges->contains($itemStockCharge)) {
$this->itemStockCharges[] = $itemStockCharge;
$itemStockCharge->setItem($this);
}
return $this;
}
public function removeItemStockCharge(ItemStockCharge $itemStockCharge): self
{
if ($this->itemStockCharges->contains($itemStockCharge)) {
$this->itemStockCharges->removeElement($itemStockCharge);
// set the owning side to null (unless already changed)
if ($itemStockCharge->getItem() === $this) {
$itemStockCharge->setItem(null);
}
}
return $this;
}
}
ItemRepository.php
<?php
namespace App\Repository;
use App\Entity\Item;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
/**
* @method Item|null find($id, $lockMode = null, $lockVersion = null)
* @method Item|null findOneBy(array $criteria, array $orderBy = null)
* @method Item[] findAll()
* @method Item[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ItemRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Item::class);
}
public function findItem()
{
return $this->createQueryBuilder('a')
->andWhere('a.blocked = :val')
->setParameter('val', false)
->orderBy('a.name', 'ASC')
->getQuery()
->getResult()
;
}
public function findBlockedItemCount()
{
return $this->createQueryBuilder('item')
->select('item, SUM(stocks.count) as sums')
->andWhere('item.blocked = :val')
->setParameter('val', true)
->leftJoin('item.itemStocks', 'stocks')
->groupBy('item')
->orderBy('item.name', 'ASC')
->getQuery()
->getResult()
;
}
public function findItemCount(){
return $this->createQueryBuilder('item')
->select('item, SUM(stocks.count) as sums')
->andWhere('item.blocked = :val')
->setParameter('val', false)
->leftJoin('item.itemStocks', 'stocks')
->groupBy('item')
->orderBy('item.name', 'ASC')
->getQuery()
->getResult()
;
}
}
最佳答案
IDE 现在有办法知道 $em->getRepository(Item::class);
将返回 ItemRepository
,因为直到运行时才解决。
注入(inject) ItemRepository
而不是实体管理器,在任何情况下都是更好的做法:
public function listItems(ItemRepository $itemRepository): Response
{
$items = $itemRepository->findItemCount();
// etc
}
关于php - "Warning: Potentially polymorphic call"在实体存储库上调用方法时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66458802/
即使图中没有循环,BGL 的 depth_first_search 算法有时也会对访问者调用 back_edge()。根据后边缘的定义,以及根据 Boost 的 DFS Visitor Documen
所以,我有一个可以从大约四个不同函数调用的例程。我想要做的是遍历可能调用此例程的路线。 我正在使用 Eclipse。我认为这一定是有可能的,因为我知道我可以手动完成此操作,尽管速度很慢。 最佳答案 在
Xcode 的分析器提示存在“对象的潜在泄漏”。以下方法中的第一行被突出显示: - (void)retrieveBeginRestoreData { self.restoreContext =
我目前正在扩展 lavalamp plugin在下拉菜单上工作,但我遇到了一个小问题。我需要知道隐藏元素的 offsetWidth。现在显然这个问题没有意义,而我正在寻找的是元素的 offsetWid
在“窗口”>“首选项”>“常规”>“搜索”下,有“忽略潜在匹配项”选项 它有什么作用?无论我是否激活它,我都看不出有什么区别。 它是一个仅对 Java 开发有意义的选项(我从不这样做,但我确实使用 E
当我运行以下函数时,出现此错误: “错误:潜在的无限循环。” 问题似乎是我在拼接方法中使用的“0”,因为当我将其更改为任何其他数字(1 - 9)时,我不会收到此错误。 我不确定这将如何创建无限循环。
我有一个 Web API 项目。我的端点之一允许进行字符串搜索,其中可能包含特殊字符。 [RoutePrefix("api/Search")] [ValidateInput(false)] // th
嗨, 我运行了 XCode 分析器 - 它告诉我以下两者都是潜在的内存泄漏。我不知道为什么。我像这样声明了 midiDevices @property (assign, nonatomic) NSMu
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: A potentially dangerous Request.Form value was detected fr
我需要解决一个编译器发现的错误——我理解为什么它会发现那个错误但需要解决它因为函数(抛出错误)只会在指针是 已初始化。 这是我的伪代码: if (incoming_message_exists) {
在调用 isDataMatchingnamespace 时,我得到了 this 的潜在无效用法如何克服以及如何以正确的方式调用 isDataMatchingnamespace? function Cl
documentation for the Cwd module声明 fast_abs_path是“更危险但可能更快的 abs_path 版本”。它以什么方式危险?什么情况下比较快?行为是否因平台而异
MSVC 对潜在未初始化变量的警告并不是特别好,特别是它错误地声称 i 可以在此程序中未初始化: #include enum class Color{ Red, Green }; in
我的实体 Item 有一个存储库 (ItemRepository),函数为 findItemCount()。当我使用 $repository = $em->getRepository(Item::cl
我的实体 Item 有一个存储库 (ItemRepository),函数为 findItemCount()。当我使用 $repository = $em->getRepository(Item::cl
我的 Eclipse 发出以下警告: Potential resource leak: '' may not be closed ...对于表达式 new BufferedWriter(...)在下面
您认为解决以下问题时的最佳实践是: MyClass myVariable = null; if ( ..condition 1.. ) { myVariable = new MyClass(1);
创建 Funds 时或 Assets表,我经常遇到同样的问题:不是全部Assets具有相同的标识符。 例如:70% 有 ISIN ,有些有彭博代码,有些两者都有,有些只有 AccountingID来自
我遇到了错误 A potentially dangerous Request.Form value was detected from the client 当我部署我的应用程序时(当我通过本地主机运
使用 this 中的一些指导在关于理解决策树结构的 scikit-learn 教程中,我的想法是,也许查看两个连接节点之间发生的特征组合可能会提供一些关于潜在“交互”术语的见解。也就是说,通过查看给定
我是一名优秀的程序员,十分优秀!