Answer the question
In order to leave comments, you need to log in
When I create a constructor in a class, I get an error Type error: Too few .. why?
I'm trying to learn DI and when I create a constructor in a class I get this error
Type error: Too few arguments to function Blog\AboutBundle\Controller\DefaultController::__construct(), 0 passed in C:\webserver\data\htdocs\essence\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller \ControllerResolver.php on line 198 and exactly 1 expected
class DefaultController extends Controller
{
private $service;
public function __construct(RenameService $service)
{
$this->service = $service;
}
}
Answer the question
In order to leave comments, you need to log in
Actually the problem is that you are injecting into the controller through the constructor.
I would recommend declaring the controller as a service - if that's what you want to do.
Or, get the service through the ServiceLocator, i.e. $this->get('some.service.id').
Info: symfony.com/doc/current/controller/service.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question