0

I am trying to understand symfony's routing system.

In app/config/routing.yml, I have two routing configurations from two different bundles '

firstbundle:
    resource: "@FirstBundle/Resources/config/routing.yml"
    prefix:   /api

secondbundle:
    resource: "@SecondBundle/Resources/config/routing.yml"
    prefix:   /api

`

So if I am making a request like,

https://example.com/app.php/api/images/ (defined in first bundle config)

or

https://example.com/app.php/api/views/ (defined in second bundle config)

How does the router decide which bundle to use?

Suppose I am going to access api./views, in this case will it also check within FirstBundle routing config? My doubt is regarding the routing flow. Does router traverse through every bundle configurations?

RunningAdithya
  • 1,656
  • 2
  • 16
  • 22
  • 1
    Symfony builds (and caches) a single list of all routes. Bundle information is not retained. bin/console debug:router can help. I might add that unless you plan on packaging and reusing your bundles in other applications individually then there is little reason for multiple bundles. – Cerad Aug 24 '17 at 13:01

1 Answers1

2

Routes, as other configuration parameters, are parsed in the same order they appear in your file.

That means that if two identical routes (keys, speaking more in general) are defined, the first one defined (and so parsed) is the one that is taken.

If you're worry about performances, I can tell that this is not something you should worry about (them are cached)

DonCallisto
  • 29,419
  • 9
  • 72
  • 100