V
V
Vladislav2021-11-17 12:36:26
symfony
Vladislav, 2021-11-17 12:36:26

Routing according to file path?

I have N number of controllers in the folder Controller/Api/v1/*
Let's say BrandController and ClientController
How can I make it so that the URLs are the following
/api/v1/client
/api/v1/brand

I know only such an option that you can do this:

/**
 * @Route("/api/v1")
 */
class ClientController extends AbstractController
{}


But then I will have to write this route to each controller, and v1, and if I forgot somewhere. it would be nice if he took from the name of the folder in which the controllers are located.
Or in the route file, you can probably specify something, but I did not find it. Something like:
api_v1:
  path: /api/v1
  resource: Controller/Api/v1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-11-17
@myks92

config/routes/annotations.yaml

api:
    resource: ../../src/Http/Controller/Api/
    prefix: /api
    name_prefix: api.
    trailing_slash_on_root: true
    type: annotation
    defaults:
        _format: json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question