views:

88

answers:

3

I have the following in my app/frontend/config/routing.yml

homepage: url: / param: { module: main, action: index }

default_index: url: /:module param: { action: index }

default: url: /:module/:action/*

sf_guard_register: url: /register param: { module: user, action: register }

sf_guard_signin: url: /login param: { module: sfGuardAuth, action: signin }

sf_guard_signout: url: /logout param: { module: sfGuardAuth, action: signout }

sf_guard_password: url: /request_password param: { module: sfGuardAuth, action: password }

When I try the /register route, I get this : Action "register/index" does not exist. I should specify, I don't have a "register" module, and my user module is working well if called manually. Plus the other routes are working fine.

any ideas are welcomed, thank you!

PS: Please ignore the spacing, I can't get the section to work

+1  A: 

Routes are processed in the order they are listed in your routing.yml file. Thus, the url /register matches the default_index route before it gets to sf_guard_register. Both default_index and default should go at the bottom of your routing.yml file.

jeremy
+2  A: 

In line with jeremy's answer:

Because your default_index route is placed above, going to /register causes this route to match. Since it is located before the sf_guard_register route, only the first match "counts".

Your routing.yml should look like this:

sf_guard_register:
  url: /register
  param: { module: user, action: register }

sf_guard_signin:
  url: /login
  param: { module: sfGuardAuth, action: signin }

sf_guard_signout:
  url: /logout
  param: { module: sfGuardAuth, action: signout }

sf_guard_password:
  url: /request_password
  param: { module: sfGuardAuth, action: password }

homepage:
  url: /
  param: { module: main, action: index }

default_index:
  url: /:module
  param: { action: index }

default:
  url: /:module/:action/*

Also, there are a number of best-practises that you might want to follow:

  1. Disabling the default routes and relying solely on named routing such as @homepage is faster than having symfony figure out which route to match when using url_for or link_to helpers. Therefore, disable the default routing and create the routes yourself. Then, use the name of the route when generating URLs.
  2. The routes used most often should be placed at the top, for example if you have a register link on all pages, you should place sf_guard_register at the top.

Just my 5 cents - hope you find it useful ;-)

phidah
Thank you very much, your solution works, and your suggestions are quite savvy. :)
A: 

You should even delete the 2 default routes :

default_index:
  url: /:module
  param: { action: index }

default:
  url: /:module/:action/*

As it is bad practice to use them, and should always create a specific route.

The best way to add routes, is to PREPEND them to you file, adding each new route at the very top.

Also, a good way to debug your routing in frontend is to run :

symfony app:routes frontend

so you will see wich route maches what (and its requirements if any)

vinyll