Yeah, I'm a bit iffy on taking specific actions on the pages as well,
but they aren't static content. I need some way of interacting with
the controllers that modify the content that won't leave the end user
confused as to which page their changes will show up on. But that
feature is still somewhat provisional until I know for certain I can
do it without breaking everything.

Thanks for the code snippets, the SQL in particular should prove
extremely helpful. While I'd rather not push the find logic into one
of my models (since that would require a route that gobbles up
everything) I'll probably end up trying something similar in the
routes file. What I'm hoping is that I'll have access to my Model at
that point (or at least be able to build the necessary access). If I
do, I'll be able to use the Tree behavior to build a list of all the
current paths and then connect those paths directly to the correct
controller/action/etc. Then I'd just need to figure out how to cache
these results until the page hierarchy changes. (This is an I idea I
had while I was asleep, so I won't be surprised if it turns out to not
work at all. In that case I probably will end up pushing the entire
path into a find method on the model.)

On Feb 4, 11:48 am, brian <[email protected]> wrote:
> On Wed, Feb 4, 2009 at 11:51 AM, Dwayne <[email protected]> wrote:
>
> > 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/abd4ffcb...)
> > 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).
>
> I did something similar. It wasn't multi-site, though. I created a
> Content model with this method:
>
> function findIdByPath($path, $lang)
> {
>         $parts = explode('/', $path);
>         $slug = array_pop($parts);
>
>         $sql = 'SELECT c.id FROM contents c ';
>         $num_parents = count($parts);
>
>         for ($i = 1; $i <= $num_parents; $i++)
>         {
>                 $parent = array_pop($parts);
>                 $sql .= "LEFT JOIN contents p${i} ON p${i}.name_${lang} = 
> '${parent}' ";
>         }
>
>         $sql .= "WHERE c.slug_${lang} = '${slug}'";
>
>         return Set::extract($this->query($sql), '{n}.c.id');
>
> }
>
> The Content model uses TreeBehavior to deal with the hierachy. I
> originally thought to give the table a field for the entire
> path/route, but ended up simply storing the slug for each page. Thus,
> I pop that off the end of the path array and each successive part is
> the slug for a parent.
>
>  The controller called it like:
>
> function display()
> {
>         if (!func_num_args()) $this->redirect('/');
>         $path = func_get_args();
>
>         $id = $this->Content->findIdByPath($path, $this->lang);
>
> I had some issues with the fact that the site has 3 languages. This is
> why the line above is fetching just the ID at this point. There is
> much more after that  to deal with getting the correct content,
> language-wise, as well as fetching links to alternative content (eg.
> offer links to Spanish & French content when there is no English
> version) for a given route.
>
> Looking at it now I see that it could all really use some refactoring.
>
> As for having actions in the path, I can't help you there. That
> doesn't seem like something that should be mixed in with this sort of
> database-served static content. It should have its own controller. Or
> maybe I misunderstood.
>
> > 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to