On Wed, Jul 14, 2010 at 5:42 AM, alopes <adrianolopesfrei...@gmail.com> wrote: > Hello, > > How i can route my URLs without showing the ID in the URL. For example > i have: > > www.mywebsite.com/id-article-title.html and i want only > www.mywebsite.com/article-title.html
Add a column to your table to hold the "slug", which will be the title string after it's been set to lowercase and all spaces converted to hyphens (or underscores). Then add SluggableBehavior to your model. See here: http://bakery.cakephp.org/articles/view/sluggable-behavior Set up a route: Router::connect( '/articles/:slug', array( 'controller' => 'articles', 'action' => 'view' ), array( 'slug' => '[-a-z0-9]+', 'pass' => array('slug') ) ); Note that the URL begins with '/articles/'. It can be whatever string you want but if you leave it out (so that the URL begins with the slug), you'll have to create a route for every other controller action in your app or every request will be sent to ArticlesController. public function view($slug = null) { if (empty($slug)) { // redirect ... } $data = $this->Article->find( 'first', array( 'conditions' => array('Article.slug' => $slug) ) ); ... } 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en