0

I have at the moment two controllers.

  • GitlabAuthController
  • UserController

I need to add the path prefix api to UserController only.

Before I was trying following at annotations.yaml file:

controllers:
    resource: ../../src/Controller/
    type: annotation
    prefix: api

But this adds the prefix to all my controllers.

Is there any way I can add the exception for the GitlabAuthController?

yivi
  • 42,438
  • 18
  • 116
  • 138
nas
  • 2,289
  • 5
  • 32
  • 67

1 Answers1

2

Just create different directories/namespaces for the different types of controllers.

Then you can do:

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

api_controllers:
    resource: ../../src/Controller/Api
    type: annotation
    prefix: api

Routes defined on the Api namespace would get the /api/ prefix, while the other routes would remain unaffected.

You can check the generated routes are fine by executing bin/console debug:router.

yivi
  • 42,438
  • 18
  • 116
  • 138
  • Do i need to create a folder Api inside the Controller folder? – nas Jan 09 '20 at 10:45
  • If you are going to use the above configuration, yes. And the controllers you put in there should be in the `App\Controller\Api` namespace. – yivi Jan 09 '20 at 10:46