1
votes

I have the following routes defined in my app:

-------------------------- ---------- -------- ------ -----------------------------------
 Name                       Method     Scheme   Host   Path
-------------------------- ---------- -------- ------ -----------------------------------
 _wdt                       ANY        ANY      ANY    /_wdt/{token}
 _profiler_home             ANY        ANY      ANY    /_profiler/
 _profiler_search           ANY        ANY      ANY    /_profiler/search
 _profiler_search_bar       ANY        ANY      ANY    /_profiler/search_bar
 _profiler_info             ANY        ANY      ANY    /_profiler/info/{about}
 _profiler_phpinfo          ANY        ANY      ANY    /_profiler/phpinfo
 _profiler_search_results   ANY        ANY      ANY    /_profiler/{token}/search/results
 _profiler                  ANY        ANY      ANY    /_profiler/{token}
 _profiler_router           ANY        ANY      ANY    /_profiler/{token}/router
 _profiler_exception        ANY        ANY      ANY    /_profiler/{token}/exception
 _profiler_exception_css    ANY        ANY      ANY    /_profiler/{token}/exception.css
 _twig_error_test           ANY        ANY      ANY    /_error/{code}.{_format}
 api_route                  ANY        ANY      ANY    /api
 sec_events_index           GET        ANY      ANY    /sec/events/
 sec_events_new             GET|POST   ANY      ANY    /sec/events/new
 sec_events_show            GET        ANY      ANY    /sec/events/{id}
 sec_events_edit            GET|POST   ANY      ANY    /sec/events/{id}/edit
 sec_guest_delete           ANY        ANY      ANY    /sec/guest/{id}
 sec_events_delete          DELETE     ANY      ANY    /sec/events/{id}
 pub_event                  ANY        ANY      ANY    /{id}/{guestid}
 home_page                  ANY        ANY      ANY    /
 about_page                 ANY        ANY      ANY    /about
 products_route             ANY        ANY      ANY    /products
 sec_guests_new             GET|POST   ANY      ANY    /sec/guests/new
 sec_guests_edit            GET|POST   ANY      ANY    /sec/guests/{id}/edit
 send_invite                ANY        ANY      ANY    /sec/invites
 admin_index                GET        ANY      ANY    /admin/users
 profile_show               ANY        ANY      ANY    /sec/profile
 admin_edit                 GET|POST   ANY      ANY    /admin/{id}/edit
 sec_delete                 DELETE     ANY      ANY    /admin/{id}
 login_route                ANY        ANY      ANY    /login
 login_check                ANY        ANY      ANY    /login_check
 pass_reset                 ANY        ANY      ANY    /reset
 pass_reset_form            ANY        ANY      ANY    /{token}
 test                       ANY        ANY      ANY    /test
 homepage                   ANY        ANY      ANY    /
 logout                     ANY        ANY      ANY    /logout
-------------------------- ---------- -------- ------ -----------------------------------

Whenever I access route profile_show via browser with /sec/profile the profiler tells me it tries to access route pub_event as if I had typed /{id}/{guestid} in my browser.

Is there something I am doing wrong to make it pick up the proper route and the correct controller and method?

1

1 Answers

2
votes

You need to move your route pub_event at end of imported routes in routing.yml.

This is normal behaviour as /sec/profile matches /{id}/{guestid}. Good practice is to load generic routes at end of routing.yml file.

Other thing what you can do is setting requirement for id parameter in pub_event route.

With annotations it should look like that:

/**
 * @Route("/{id}/{guestid}", requirements={"id" = "\d+"}, defaults={"id" = 1})
 */

Remember that "Earlier Routes always Win". Read more about requirements in Symfony Routing book: http://symfony.com/doc/current/book/routing.html#adding-requirements