On Thu, Feb 12, 2009 at 5:57 PM, Miles J <[email protected]> wrote:
>
> Im trying, for example, to get this:
>
> /games/view/123/Starcraft
>
> To route to:
>
> /games/view/Starcraft
>
> But still pass the id to the action. Heres my route, but its not
> working:
>
> Router::connect('/games/view/:title', array('controller' => 'games',
> 'action' => 'view'), array('pass' => array('id', 'title'), 'id' =>
> '[0-9]+', 'title' => '[a-zA-Z0-9_-]+'));

But there's no ID in that route to pass to the controller; there's
only the title.

You might want to consider using a slug. Basically, you'd create a
slug--all lowercase and spaces as hyphen or underscore--from the title
for each game.Your route would be almost the same:

Router::connect(
        '/games/view/:slug',
        array('controller' => 'games', 'action' => 'viewBySlug'),
        array(
                'pass' => array('slug'),
                'slug' => '[a-z0-9_-]+'
        )
);

Then, you can simply do $this->Game->findBySlug($slug) and you'll have your ID.

I recommend you keep your slugs all lowercase so I've changed the
regexp to reflect that. That's entirely up to you, though.

Give the slug column a UNIQUE index, also.

--~--~---------~--~----~------------~-------~--~----~
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