Search code examples
phpsymfonyroutessymfony4

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


Solution

  • In your config/services.yaml

    App\DirectoryA\Controller\: # assuming you have namespace like that
        resource: '../src/DirectoryA/Controller'
        tags: ['controller.service_arguments']
    App\DirectoryB\Controller\: # 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