tags:

views:

393

answers:

2

Hi,

I'm trying to create a route that will "cover" this kind of URLs:

www.test.com/parent1/parent2/parent3/item

www.test.com/parent1/parent2/parent3/parent4/item1

Number of those parents in unspecified, and it should only serve to give a better, more intuitive look to site URLs. Main parameter is that "item".

I suppose that only way to solve that is to use Route_Regex, and so I tried to accomplish this route task with something like this:

routes.test.type = "Zend_Controller_Router_Route_Regex"
routes.test.route = "test/(?:.*)?([^\/]+)"
routes.test.defaults.module = default
routes.test.defaults.controller = test
routes.test.defaults.action = index
routes.test.map.1 = "path"
routes.test.map.2 = "item"
routes.test.reverse = "test/%s%s"

I haven't been testing this to much, because I'm not sure if I'm doing the right thing... I have no idea how that regex should even look like, and how should I treat that "path".

Can you advice what should I do to fulfill this kind of route demand? So, I need that path (parent1, parent2, etc.) only for appearance, and main param is that "item"...

Thanks,

Nikola

A: 

I don't know what zend route is (something php related?), but if you can use normal programming functions then a much simpler solution than a regex is to use built-in list/split functions, eg:

end(explode($Url,'/'))

Url.split('/').last()

ListLast(Url,'/')

etc


If you do need a regex, you can do it simply with this:

[^/]+$

That will give you everything after the last forward-slash upto the end of the line.
(You only need to escape the / with a backslash if you're using it in a context which requires escaping.)


(btw, in your example, you've got test/ at the start - is that deliberate/required?)

Peter Boughton
A: 

Yeah, but I don't need that... :)

Zend_Controller_Route is a Zend Framework component. I'm currently working on one project using Zend Framework and I need to create custom route in form that I've described in my first post.

alokiN