I knew it had to be something simple! :) So basically, adding the 'slug' => before passing the actual slug fixed it.
Now I need to work some more magic to have site.com/page/sub-page routing :) Thanks a lot, cricket ;) On Jan 27, 6:19 pm, cricket <[email protected]> wrote: > On Wed, Jan 26, 2011 at 9:22 AM, r4zv4n <[email protected]> wrote: > > > If I insert the link the correct way: > > > $this->Html->link('Page Title', > > array('controller' => 'pages', 'action' => 'view', 'page- > > slug')); > > > I get site.com/pages/view/page-slug > > > If I hardcode it: > > > $this->Html->link('Page Title', '/page-slug/')); > > > I get site.com/page-slug (theintendedresult). > > That makes sense because you're essentially bypassing Router. > > Try this: > > Router::connect( > '/:slug', > array( > 'controller' => 'pages', > 'action' => 'view' > ), > array( > 'slug' => '[-a-z0-9]+', > 'pass' => array('slug') > ) > ); > > That should work, although it'll have to be the last route defined. > This assumes your slugs will be lowercase alphanumeric, plus hyphens. > The slug will be passed to the method as a param: > > public function view($slug = null) { ... } > > When you create the link, notice that you include the 'slug' option in > the same array as the controller & action (unlike in the route > definition). > > echo $this->Html->link( > 'foo', > array( > 'controller' => 'pages', > 'action' => 'view', > 'slug' => $slug > ), > array('title' => 'foo') > ); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
