Question

I have several urls:

  • /dave
  • /davina
  • /dave/chris
  • /davina/peter

I have entries for all of them in my routes, an example of this is:

routes.dave.route = /dave
routes.dave.defaults.module = default
routes.dave.defaults.controller = person
routes.rcp.defaults.action = index

routes.davina.route = /dave/chris
routes.davina.defaults.module = default
routes.davina.defaults.controller = person
routes.davina.defaults.action = index

I think you can see straight away that I have a duplication issue. Is there a way of combining multiple urls into a single route?

I have played around with using /:person but I also have other content aswell not going to person controller.

routes.person.route = /:personname
routes.person.defaults.module = default
routes.person.defaults.controller = person
routes.person.defaults.action = index
routes.person.reqs.personname = "^[a-zA-Z0-9]+$"

Urls such as /search?person=dave which goes off to the search controller is obviously being killed by the expression above.

Can I express the requirement as a list? "dave|davina|etc" or is there another magical zend method of doing this?

UPDATE: I was playing around and came across this partial solution:

routes.person.route = /:personname
routes.person.defaults.module = default
routes.person.defaults.controller = person
routes.person.defaults.action = index
routes.person.reqs.personname = "(dave|davina)"

routes.person.route = /:person/:personname
routes.person.defaults.module = default
routes.person.defaults.controller = person
routes.person.defaults.action = index
routes.person.reqs.personname = "(chris|peter)"

I am going to run with this for the moment as is satisfies my requirements but I will leave this open(at least for a day) for anyone to offer there advice. The main issues is that both lists are going to grow, which will eventually cause an issue.

Was it helpful?

Solution

I think I may have the anwser for that.

In ZF, the routes are matched in reverse-order. So the last defined route, is the first matched.

In this case, you should define your /:person/:personname route, then define the others static routes like about page, contact page, etc.

If I understand Zend correctly, it should work. This do that in clear:

url=/about
match route "/about"

url=/david/parker
match route "/:person/:personname"
not "/about" or "/contact"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top