I don't know if this is possible. I've tried so many different regex combinations and I come up with nothing. So, here's my problem...
I have a product page that needs to display products based on a category (which can be nested to infinite, but most likely 3 levels max), a sort column (with order, ASC or DESC), filters (i.e. manufacturer, this will be key/value pairs), tags (a simple list of a words (\w) that can contain spaces), and finally a page.
The category is the only required option above. Of course, every variable above needs to be captured into an array for processing.
Example UR开发者_JAVA技巧L:
http://mydomain.com/products/Home/Bedroom/Beds/sort/price/desc/filters/manufacturer/ikea/size/king/tags/black/lowprofile/wood/green/page/2
would render:
category => Home/Bedroom/Beds
sort_by => price
sort_order => desc
manufacturer => ikea
size => king
tags => Array('black','lowprofile','wood','green')
page => 2
I'm pretty sure I'm living in a dream world where this Regex is possible. Or maybe I'm looking at it the wrong way. Very possible as I've been staring at it for quite some time.
Any takers? I'll just be over here banging my head against the wall.
Create a custom route which strips out all of the expected variables.
Your new route should try and match
products/*/param1/value1/param2/value2/etc.
If you know what the first param name is, or even any of them, you can begin stripping out pieces of the URL which should leave you with what is dynamic (explode with /, loop, breaking on first known param).
Here's an explanation on actually creating a custom route: how to get dynamic URL like mydomain.com/username using zend framework
IMO you're doing it the wrong way. You should have a "cleaner" route:
/products/*
If route is matched, get the $_SERVER['request_uri']
, strip /products/
from the begining and parse the categories. Add the parameters in "form" syntax (?param1=a¶m2=b
).
精彩评论