小编kjg*_*kjh的帖子

Symfony 4:无法自动装配参数 $manager of ... 它引用接口“Doctrine\Common\Persistence\ObjectManager”

当我提交表单时出现此错误:

无法自动装配“App\Controller\AdController::create()”的参数 $manager:它引用接口“Doctrine\Common\Persistence\ObjectManager”,但不存在这样的服务。您可能应该将此接口别名为现有的“doctrine.orm.default_entity_manager”服务。

这是在 AdController.php 中的函数 create 中:

<?php

namespace App\Controller;

use App\Entity\Ad;
use App\Form\AdType;
use App\Repository\AdRepository;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class AdController extends AbstractController
{
    /**
     * @Route("/ads", name="ads_index")
     */
    public function index(AdRepository  $repo)
    {
        $ads = $repo->findAll();

        return $this->render('ad/index.html.twig', [
            'ads' => $ads,
        ]);
    }

    /**
     * @Route("/ads/new", name="ads_create")
     * 
     * @return Response
     */

    public function create(Request $request, ObjectManager $manager){
        $ad = new Ad();



        $form = $this->createForm(AdType::class, $ad); …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

doctrine-orm ×1

php ×1

symfony ×1