Symfony 4:我无法在我的bundle构造函数中自动装配

时间:2018-02-27 06:07:25

标签: php symfony service entitymanager symfony4

位于PagesController的我的控制器vendor/dovstone/symfony-blog-admin/src/Controller包含以下代码:

<?php 

//...

class PagesController extends Controller 
{

    private $em;

    public function __construct(EntityManagerInterface $em)
    {
        $this->em = $em;
        dump($em) // return null;
    }

    // ...

Symfony抛弃了我:Type error: Too few arguments to function DovStone\Bundle\BlogAdminBundle\Controller\PagesController::__construct(), 0 passed in C:\Apps\Web\sf4\vendor\symfony\http-kernel\Controller\ControllerResolver.php on line 111 and exactly 1 expected

我做错了什么?

1 个答案:

答案 0 :(得分:0)

以下是我所做的:

<?php 

//...

class PagesController extends Controller 
{

protected $container;

private $em;

public function __construct(ContainerInterface $container, EntityManagerInterface $em)
{
    $this->container = $container;

    $this->em = $em;
    dump($em); // EntityManagerInterface;
}

// ...

在此之后,我必须通过运行php bin/console cache:clear

来清除缓存