[英]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;大家好,我在一些 symfony 项目中工作,但这个错误仍然显示给我,我已将 Doctrine\Common\Persistence\ObjectManager 更改为 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
仍然无法工作,请我需要一些帮助,这是为了我的大学考试,我尝试了很多方法来解决这个问题,即使我在 stackoerflow 上查找解决方案,但我没有找到任何帮助
<?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
]);
}
}
You most likely need to use Doctrine\Persistence\ObjectManager
instead of Doctrine\Common\Persistence\ObjectManager
which has been removed in newer versions of Doctrine.您很可能需要使用
Doctrine\Persistence\ObjectManager
而不是Doctrine\Common\Persistence\ObjectManager
,后者已在较新版本的 Doctrine 中被删除。 However, there is no alias for that class (you can check that with bin/console debug:autowiring doctrine
) so I guess the easiest way would be to use Doctrine\ORM\EntityManagerInterface
.但是,该类没有别名(您可以使用
bin/console debug:autowiring doctrine
检查)所以我想最简单的方法是使用Doctrine\ORM\EntityManagerInterface
。
Try this.尝试这个。
<?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\ORM\EntityManagerInterface;
class BlogController extends AbstractController
{
/**
* @Route("/blog", name="blog")
*/
public function index(ArticleRepository $repo): Response
{
$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, EntityManagerInterface $manager)
{
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")
*/
public function show(Article $article)
{
return $this->render("blog/show.html.twig", [
'article' => $article
]);
}
}
我有同样的问题,这是新的路径:
use Doctrine\Persistence\ObjectManager;
There are no classes related to persistence in the Doctrine\Common
namespace. Doctrine\Common
命名空间中没有与持久性相关的类。 So you have to use ie Doctrine\DBAL .所以你必须使用即Doctrine\DBAL 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.