Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2008, 02:39 PM
Junior Member
 
Join Date: Jul 2008
Posts: 2
Default Routing with variable number of parameters

I want to implement SEO URLs in my application, of the type:
http://www.mysite.com/archive/2008_apr_5

This is easy to do using a regex route, EG:
Code:
routes.archive.type = "Zend_Controller_Router_Route_Regex"
routes.archive.route = "archive/([1|2][0-9]{3})_([^_]+)_([0-9]{,2})"
routes.archive.reverse = "archive/%d_%s_%d"
routes.archive.defaults.module = "archive"
routes.archive.defaults.controller = "index"
routes.archive.defaults.action = "index"
routes.archive.map.1 = "year"
routes.archive.map.2 = "month"
routes.archive.map.3 = "day"
The catch is I want the number of parameters to change, that is, all this links will go to the same controller and same action but with a different set of request parameters:
http://www.mysite.com/archive/2008_apr_5
http://www.mysite.com/archive/2008_may
http://www.mysite.com/archive/2007
http://www.mysite.com/archive/

So the question is, what is the best way to achieve this. I can think of 2 options:
  1. Have multiple regex routes, one for each parameters count, each having a different name
  2. Write my own custom 'multi-regex' route which knows how to handle these options
None of these options are perfect though...

Any thoughts anyone?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-11-2008, 04:06 AM
Member
 
Join Date: Jul 2008
Posts: 60
Default

Instead of multiple routing rules, you can probably handle use a more advanced regex. Making the different sections optional. Something like:
Code:
archive/(?:([12][0-9]{3})(?:_([^_]+)(?:_([0-9]{1,2}))?)?)?$
Then setting defaults for the year, month and day values if they aren't present should do the trick.
__________________
Brenton Alker
Brisbane, Australia

http://blog.tekerson.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-11-2008, 09:32 AM
Junior Member
 
Join Date: Jul 2008
Posts: 2
Default Thanks

This should work great for one direction (the matching).
But if I get it right the reverse (assembling) will still always need the full number of parameters?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:18 AM.