Awesome, thanks a million for a thorough explanation. I will try this out!!!!
On Aug 4, 11:47 am, cricket <[email protected]> wrote: > On Wed, Aug 4, 2010 at 12:38 PM, spheroid <[email protected]> wrote: > > Thanks, but how would it know what to render? Example, if the page > > needs to show blog article #23, effectively I need to pass that > > variable somehow. If the url were mysite.com/blogs/view/23 the > > controller would handle that. > > What you're trying to do is to use slugs for your URLs. You'll have to > create a column in the table to hold your slug. Usually, that's a > string taken from a title, name, etc. Then, use the slug to fetch the > record, eg. 'conditions' => array('slug' => $slug) > > The simplest way to do this is to use SluggableBehavior [1] You tell > it which field/column to use to create the slug. When you save a new > record, it'll add the slug. > > Say you have a PostsController, and you want your posts URLs to look like: > > http://www.yoursite.com/news/this-is-a-slug > > Route: > > Router::connect( > '/news/:slug', > array('controller' => 'posts', 'action' => 'slug'), > array('slug' => '[-a-z]+', 'pass' => array('slug')) > ); > > You might need to change the regexp to [-_a-z] if you want to include > underscores. Or [-a-z0-9] if numbers may be involved. > > function view($slug = null) > { > ... > > Note that you must also include routes for your add/edit/admin_* > actions, too, as the regexp will otherwise match those. And they must > come before the slug route. > > In your case, you want the slug to be the entire URL. eg: > > Router::connect( > '/:slug', > array('controller' => 'posts', 'action' => 'slug'), > array('slug' => '[-a-z]+', 'pass' => array('slug')) > ); > > The problem with this is that you'll have to create routes for EVERY > controller action in your app. > > Be sure to fetch the slug field along with your other data so you can > then create links with: > > $html->link( > $data['Post']['title'], > array( > 'controller' => 'posts', > 'action' => 'view' > 'slug' => $data['Post']['slug'] > ) > ); > > [1]http://cake-syrup.sourceforge.net/ingredients/sluggable-behavior/ > Be sure to follow the link to the Bakery tutorial. 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 [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
