Monday, March 1, 2010

Re: Routing first parameter in URL to an action

No dice :-(

Here's my view method:

function view($slug) {
$post = $this->Post->findBySlug($slug);
$postTitle = $post['Post']['title'];
$this->set(array(
'post'=>$post,
'pageheader'=>$postTitle
));
}

Anything I'm missing?


On Mar 1, 5:55 pm, Lucca Mordente <luccamorde...@gmail.com> wrote:
> 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...@gmail.com> 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@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: