'Class Doctrine\Common\Persistence\ObjectManager does not exist
hi guys so im working in some symfony project and this error still display to me i have changed the Doctrine\Common\Persistence\ObjectManager to Doctrine\ORM\EntityManagerInterface; and still not working please i need some help it's for my university exams i tried alot to fix this issues even i look it up to stackoerflow about a solution but i didn't find anything can help
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Article;
use App\Repository\ArticleRepository;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Persistence\ObjectManager;
class BlogController extends AbstractController
{
/**
* @Route("/blog", name="blog")
*/
public function index(ArticleRepository $repo): Response
{
// $repo = $this->getDoctrine()->getRepository(Article::class);
$articles = $repo->findAll();
return $this->render('blog/index.html.twig', [
'controller_name' => 'BlogController',
'articles' => $articles
]);
}
/**
* @Route("/",name="home")
*/
public function home(){
return $this->render("blog/home.html.twig",[
"title"=> "miral",
"age" => 31
]);
}
/**
* @Route("/blog/new", name="blog_create")
*/
public function create(Request $request, ObjectManager $manager){
dump($request);
if($request->request->count() > 0){
$article = new Article();
$article->setTitle($request->request->get('title'))
->setContent($request->request->get('content'))
->setImage($request->request->get('image'));
$manager->persist($article);
$manager->flush();
}
return $this->render("blog/create.html.twig");
}
/**
* @Route("/blog/{id}",name="blog_show")
*/
//ArticleRepository $repo, $id
public function show(Article $article){
//$repo=$this->getDoctrine()->getRepository(Article::class);
// $article= $repo->find($id);
return $this->render("blog/show.html.twig",[
'article' => $article
]);
}
}
Solution 1:[1]
There are no classes related to persistence in the Doctrine\Common namespace. So you have to use i.e. Doctrine\DBAL.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David |
