Thursday, July 30, 2009

Re: Routing /group/person/post instead of /post/id

Well the link provided should offer enough information.

One thing you could do is (out of the top of my head):

Router::connect('/:group', array('controller' => 'groups', 'action' =>
'view'));
Router::connect('/:group/:user', array('controller' => 'users',
'action' => 'view'));
Router::connect('/:group/:user/:post', array('controller' => 'post',
'action' => 'view'));

Check $this->params in your controller for the variables 'group',
'user' and 'post' and use them in combination with a find('first')
call. Note that this solution will catch the urls for other
controllers. Eg you can't access your 'help' controller with '/help'
unless you explicitly define a route for that. One way around this is
to add a constant at the beginning of your routes

Router::connect('/view/:group')
etc

But there are also many other routing solutions. Such as:

Router::connect('/:group/:user/:post', array('controller' =>
'controller-that-handles-all-levels', 'user' => null, 'post' =>
null));

or even:

Router::connect('/*', array('controller' => 'controller1'));

-> define in Controller1Controller: public function index($group =
null, $user = null, $post = null)

So basically what you want is possible and there are lots of
possibilities.

-Roel

On 30 jul, 00:50, Orson <ors...@gmail.com> wrote:
> I didn't see this situation explained there.
>
> It would need to look up the group, then lookup the person associated
> with that group, then lookup the post associated with that user before
> it could tell the posts controller which post to show.
>
> Ex.:http://example.com/dev/miker/grilled-fish/
> Lookup dev group, find mike,
> Lookup mike user, find post grilled-fish
> call posts controller for id xx associated with grilled-fish
>
> Hopefully that makes more sense.
--~--~---------~--~----~------------~-------~--~----~
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: