1

I use modules layout to structure my controllers:

:module/:controller/:action

I would like to add a new custom route so that the following url will work.

domain.com/username

where username is a username of any registered user on the website.

Can anyone point me in the right direction?

Thank you

iBiryukov
  • 1,730
  • 4
  • 19
  • 30

3 Answers3

1

See this blog post for a detailed explanation of how to do this in ZF:

http://tfountain.co.uk/blog/2010/9/9/vanity-urls-zend-framework

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
0

Not sure if you can make something like domain.com/username. Instead you could do domain.com/u/username or domain.com/user/username. For example, to make the second route in you application.ini you could put something similar to the following:

resources.router.routes.user.route = "/user/:user"
resources.router.routes.user.type = "Zend_Controller_Router_Route" 
resources.router.routes.user.defaults.module = default
resources.router.routes.user.defaults.controller = user
resources.router.routes.user.defaults.action = user
resources.router.routes.user.defaults.user = 
resources.router.routes.user.reqs.user = "\s+" 
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Not that you CAN'T do that /username URL, but your suggestion is very good. Having generic urls without any keyword is bad practise, because you end up having some junction action, that will have more logic to determine if the url is for username, for page, or anything else. It'S always better to have keyword in your URL. – Tomáš Fejfar Jun 04 '11 at 12:23
  • >>It'S always better to have keyword in your URL It's indeed better from developer's point of view. However, from the user's point of view it's much nicer to have a friendly URL for their page. @marcin I know how to deal with standard cases. My question was specifically about a non-standard one. – iBiryukov Jun 04 '11 at 23:48
-1

http://framework.zend.com/manual/en/zend.controller.router.html covers quite well all the different ways you can add routes. Keep in mind, once you add custom routes, the default one will not work anymore unless you explicitly define it (as well as in url view helpers etc.).

Niklas
  • 29,752
  • 5
  • 50
  • 71
  • I appreciate the effort. But there is no need to quote documentation. I've read it. My question was about an unusual case in route handling. – iBiryukov Jun 04 '11 at 23:49