So, here is a controller I've just built:
namespace MDP\API\ImageBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class RetrieverController {
private $jsonResponse;
private $request;
public function __construct(JsonResponse $jsonResponse, Request $request) {
$this->jsonResponse = $jsonResponse;
$this->request = $request;
}
/**
* @Route("/image/{amount}")
* @Template("MDPAPIImageBundle:Retriever:index.json.twig")
*/
public function retrieve($amount)
{
}
}
I want to make this controller work as a service, to use DependencyInjection. So, here is my services.xml file:
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="mdpapi_image.json_response" class="Symfony\Component\HttpFoundation\JsonResponse" />
<service id="mdpapi_image.request" class="Symfony\Component\HttpFoundation\Request" />
<service id="mdpapi_image.controller.retriever" class="MDP\API\ImageBundle\Controller\RetrieverController">
<argument type="service" id="mdpapi_image.json_response" />
<argument type="service" id="mdpapi_image.request" />
</service>
</services>
</container>
However, when I try to execute my controller, I always get this exception:
Catchable Fatal Error: Argument 1 passed to MDP\API\ImageBundle\Controller\RetrieverController::__construct() must be an instance of Symfony\Component\HttpFoundation\JsonResponse, none given, called in /home/steve/projects/APIs/app/cache/dev/jms_diextra/controller_injectors/MDPAPIImageBundleControllerRetrieverController.php on line 13 and defined in /home/steve/projects/ImageAPI/ImageBundle/Controller/RetrieverController.php line 13
When I am in dev mode, I see that Symfony generate this file in the cached files...
class RetrieverController__JMSInjector
{
public static function inject($container) {
$instance = new \MDP\API\ImageBundle\Controller\RetrieverController();
return $instance;
}
}
How can I make it so that the arguments are added correctly to the controller, like specified in my services.xml file?