Wednesday, February 4, 2009

Nested Routing for Models with Tree Behavior

I've been searching for a way to implement nested routes in cakephp.
I've seen a few threads on this (for example
http://groups.google.com/group/cake-php/browse_thread/thread/abd4ffcb3eb363a7/e33566a2a8182b46?lnk=gst&q=nested+routes#e33566a2a8182b46)
but they've all been at least a few years old so I don't know if
there's still no way to do this using a default install of cake. My
suspicion is that there isn't, but it doesn't hurt to ask.

I want this behaviour for a multi-site CMS I'm working on at the
moment. What I'd like to be able to do is have URLs of the form /
page_1/page_2/page_3/ where the number of pages is arbitrary, but
page_2 is a child of page_1 and page_3 is a child of page_2, etc.
Basically simulating how things would work with static pages in
hierarchically organized folders. This is complicated by the fact that
to enable multiple sites managed together the URL might be of the
form /site/page_1/page_2/page_3/ and that I'd also like to be able to
access specific actions on a page (so /site/page_1/page_2/page_3/
category/1 might show a specific category on page_3).

At this point I think that to enable this I'll have to put in a route
that catches everything and then split it up myself. I'd rather not do
that, but if I have to I can live with it. The problem I have is I'm
not sure what the best way would be to efficiently determine what page
I'm actually looking at. The pages are set up using the Tree behavior,
so I can get out a breadcrumb to a page pretty quickly once I know the
page, but what I need to do is the reverse. I have no idea how to do
that efficiently, especially since the path is embedded between site
and action sections in the URL, which aren't easily separated out.

Any advice on this would be appreciated. Even just a link to a good
resource explaining how cakephp routing and/or the Tree behavior works
(I'm a bit hazy on the both).

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: