即使我试图在我的propertyController中调用Doctrine包,我也有以下错误。我不知道我错过了什么。
'getDoctrine'.intelephense(1013)未定义的方法
namespace App\Controller;
use App\Entity\Property;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Doctrine\ManagerRegistry;
class propertyController extends AbstractController
{
/**
* @Route("/billets",name="property.index")
* @return Response
*/
public function index():Response{
$repostory= $this->getDoctrine()->getRepository(Property::class);
return $this->render("proprety/index.html.twig",[
'current_menu' => 'properties'
]);
}
}发布于 2022-01-04 13:12:40
应该注入EntityManager对象而不是
use Doctrine\ORM\EntityManagerInterface;..。
public function index(EntityManagerInterface $em): Response
{
$repostory = $em->getRepository(Property::class);
return $this->render("proprety/index.html.twig",[
'current_menu' => 'properties'
]);
}https://stackoverflow.com/questions/70555523
复制相似问题