1

I have the following error even i had tried to call Doctrine ORM package in my propertyController. I don't know what i have missed.

Undefined method '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'
            ]);
    }
}
Lam
  • 23
  • 1
  • 6
  • `getDoctrine()` is indeed deprecated in 5.4, but it's not removed until 6.0, so I don't think the above comment applies here. I'd review [these](https://stackoverflow.com/questions/59149877) inteliphense [questions](https://stackoverflow.com/q/59444350) instead. – msg Jan 02 '22 at 20:12

1 Answers1

1

you should inject EntityManager object instead

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'
        ]);
   }
picios
  • 250
  • 1
  • 6