【发布时间】:2023-03-18 07:35:01
【问题描述】:
我有两个 Entity 类:House 和 Car。
在实体屋类中我有方法:
<?php
namespace Acme\HouseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* House
*/
class House {
//...
public function getRandomCar()
{
$em = $this->getDoctrine()->getManager();
$car = $em->getRepository('AcmeCarBundle:Car')->find(rand(0,100));
return $car->getName();
}
}
但我无法在我的 Entity House 课程中使用 Doctrine。我该怎么做呢?
【问题讨论】:
-
在存储库类中执行此操作。
-
我知道,但是我如何在 Entity 和其他类中使用 Doctrine?
标签: php symfony doctrine-orm sonata-admin symfony-sonata