Home > Software design >  you forgot to register the controller as a service or missed tagging it with the "controller.se
you forgot to register the controller as a service or missed tagging it with the "controller.se

Time:02-21

Showing error when I calling get API in symphony

RuntimeException HTTP 500 Internal Server Error Could not resolve argument $salesteamRepository of "App\Controller\SalesController::index()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?

enter image description here

CodePudding user response:

It depends on your version of symfony. in version 6 (and maybe 5.4 as well) you don't need any extra config other then autowire: true and autoconfigure: true.

in older versions you have to tell the framework to treat your controllers as controllers with method autowiring:

# controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

https://symfony.com/doc/current/controller/service.html

CodePudding user response:

In your services.yaml file, make changes as below

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.
        public: true

Read more in details https://symfony.com/doc/current/service_container.html

  • Related