Skip to content
Advertisement

Symfony 4 – controllers in two directories

In my application, I use Symfony 4. I want Symfony to search for controllers in two directories: A and B. I found something like this:

controllers:
    resource: '../src/DirectoryA/Controller/'
    type:     annotation

, but it only works for one directory. How can I have Symfony to search for controllers in two directories?

Regards

Advertisement

Answer

In your config/services.yaml

AppDirectoryAController: # assuming you have namespace like that
    resource: '../src/DirectoryA/Controller'
    tags: ['controller.service_arguments']
AppDirectoryBController: # assuming you have namespace like that
    resource: '../src/DirectoryB/Controller'
    tags: ['controller.service_arguments']

This will add next directory for service arguments. Thats answers your questions based In directory, what you have posted is routing file, in there would be similiar

controllers_a:
    resource: '../src/DirectoryA/Controller/'
    type:     annotation
controllers_b:
    resource: '../src/DirectoryB/Controller/'
    type:     annotation
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement