Symfony 控制器作为服务无法正常工作

Symfony controller as a service not working

我有这个控制器:

<?php

namespace DnD\RaHApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class testController extends Controller
{

  private $agentRepository;

  public function __construct(AgentRepository $agentRepository)
  {
    $this->agentRepository = $agentRepository;
  }


  public function getall()
  {
    return "asdf";
  }

}

这个routing.yml:

test:
  path: /test
  defaults: {_controller: test_controller:getall}

还有这个services.yml

agent_repository:
        class: Doctrine\ORM\EntityRepository
        factory_service: doctrine.orm.default_entity_manager
        factory_method: getRepository
        arguments:
            - DnD\RaHApiBundle\Entity\Agent


test:
        class: DnD\RaHApiBundle\Controller\testController
        arguments: ["@agent_repository"]

我正在使用 fosrestbundle 开发 API。每当我点击 url: /test 时,我都会返回以下错误:

Catchable Fatal Error: Argument 1 passed to DnD\RaHApiBundle\Controller\testController::__construct() must be an instance of DnD\RaHApiBundle\Controller\AgentRepository, instance of DnD\RaHApiBundle\Repository\AgentRepository given, called in /Users/danielrvt/IdeaProjects/rentahouse/app/cache/dev/appDevDebugProjectContainer.php on line 2525 and defined

您忘记在控制器中添加 use 语句。

use DnD\RaHApiBundle\Repository\AgentRepository;