cake-php@googlegroups.com
[Top] [All Lists]

Re: Routing first parameter in URL to an action

Subject: Re: Routing first parameter in URL to an action
From: Lucca Mordente
Date: Mon, 1 Mar 2010 07:55:45 -0800 PST
if its not calling the view method, try to add  \- to your regex as
follows:

 '^[a-zA-Z0-9_\-]{1,}$'


else if the parameter just isn't being passed, add the 'pass' option
to route:

Router::connect(
     '/:slug',
     array('controller' => 'posts', 'action' => 'view'),
     array('slug' => '^[a-zA-Z0-9_]{1,}$', 'pass'=>array('slug'))
);


hope it helps (:


On 1 mar, 12:39, jbov <jonathan.li...@xxxxxxxxx> wrote:
> I have set up a blog using URL slugs. Say my domain is darn.it and the
> title for my first post is "I lost my shoe". My blog posts are
> displaying at darn.it/posts/i-lost-my-shoe. Easy as pie, er, cake.
>
> I want to route it so the first parameter in the url is the slug. So
> darn.it/i-lost-my-shoe would map to controller => posts, action =>
> view. Below is my routing, but I'm missing something because it's not
> passing the slug to the view method properly. Or maybe it's not
> calling the view method. Any advice?
>
> Router::connect(
>      '/:slug',
>      array('controller' => 'posts', 'action' => 'view'),
>      array('slug' => '^[a-zA-Z0-9_]{1,}$')
> );

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

<Prev in Thread] Current Thread [Next in Thread>