I Use Symfony 3, And I Want to understand How symfony chouses the Route.
I have 3 routes, 2 in routing.yml and 1 in annotation. this is my code:
app/config/routing.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
hello:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}
hello_name:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta, firstName: "route2"}
src/AppBundle/Controller/DefaultController.php
/**
* @Route("hello/{firstName}", name="hello", defaults={"firstName" = "Annotation"})
*/
public function rottaAction($firstName,Request $request)
{
var_dump($request->get('firstName'));
exit;
}
My result is
string 'route1' (length=6)
with this routing.yml
hello:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}
hello_name:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta, firstName: "route2"}
app:
resource: "@AppBundle/Controller/"
type: annotation
My result is
string 'route2' (length=6)
and with this combination:
hello:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta,firstName: "route1"}
hello_name:
path: "hello/{firstName}"
defaults: {_controller: AppBundle:Default:rotta, firstName: "route2"}
#app:
# resource: "@AppBundle/Controller/"
# type: annotation
my result is:
string 'route1' (length=6)