Monday, March 1, 2010

Routing first parameter in URL to an action

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@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: