DEV Community

Discussion on: Adding Products to the Cart | Building a Shopping Cart with Symfony

Collapse
 
mrgamingfrench profile image
SHINZO WO SASAGEYO

I think there is a problem here

The productManager is called without arguments, thus throwing an exception when trying to acces 'product.detail' route.

The exception is :

Type error: Too few arguments to function App\Manager\CartManager::__construct(), 0 passed in C:\Projets Symfony\projetValentin\var\cache\dev\ContainerEq4lpi1\getServiceLocator_Frm8o4fService.php on line 9 and exactly 3 expected

Collapse
 
qferrer profile image
Quentin Ferrer

Hello. I use the autowiring of Symfony, so I don't need to manage service dependencies.

Autowiring allows you to manage services in the container with minimal configuration. It reads the type-hints on your constructor (or other methods) and automatically passes the correct services to each method.

To enable it, make sure that your config/services.yaml file configuration is like that:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mrgamingfrench profile image
SHINZO WO SASAGEYO

Of course !

How did I not think about that before ?

Been doing symfony for 4 years now and still forgetting basics lol .

Thx for the help. Much appreciated !