F
F
Flasher2017-10-12 17:21:32
symfony
Flasher, 2017-10-12 17:21:32

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

3 answer(s)
V
Viktor Yanyshev, 2017-10-12
@villiwalla

You seem to clearly write that there are 0 arguments

A
Anton, 2017-10-12
@Eridani

Some interesting parameters you have in the constructor come

A
Alexander Kuznetsov, 2017-10-13
@DarkRaven

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 question

Ask a Question

731 491 924 answers to any question