Reputation: 18729
I am migrating an existing Symfony 2.8
project to Symfony 3.4
. After adding the existing AppBundle
to a fresh generated Symfony 3.4
project I the following error:
Cannot autowire service "AppBundle\Controller\CustomExceptionController": argument "$useDebugMode" of method "__construct()" is type-hinted "bool", you should configure its value expl icitly
I found several other questions about this problem, but the solution always points to missing parameters in the service.yml
file. However, as far as I can tell, this is not the problem here:
// CustomExceptionController.php
namespace AppBundle\Controller;
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
...
class CustomExceptionController extends ExceptionController {
public function __construct(\Twig_Environment $twig, bool $useDebugMode, Translator $translator) {
parent::__construct($twig, $useDebugMode);
...
}
...
}
// services.yml
services:
...
app.exception_controller:
class: AppBundle\Controller\CustomExceptionController
arguments: ['@twig', '%kernel.debug%', "@translator.default" ]
I did not explicitly set/define %kernel.debug%
in the app/config/config.yml
but I assume that this is not necessary. Is it?
Thus the value of the $useDebugMode
parameter IS set explicitly to the value of %kernel.debug%
. So how to solve the error?
Upvotes: 0
Views: 1310
Reputation: 946
// services.yml
services:
...
app.exception_controller:
class: AppBundle\Controller\CustomExceptionController
arguments:
$useDebugMode: '%kernel.debug%'
Specify only $useDebugMode
in your arguments list, other two will get autoinjected/autowired.
The $useDebugMode
must be the same as in constructor.
Upvotes: 2