Re: How to use SEO urls in CakePHP without the ID?

2010-08-05 Thread bradmaxs
Hi Cricket,

Thanks for the reply about the behavior being compatible with 1.3.  It
sure is and what a great behavior it is.  I got it up and running in
under 5 minutes with NO hassle.  Something that happens almost never
for me:)

Brad



On Jul 14, 9:12 am, cricket zijn.digi...@gmail.com wrote:
 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.htmland 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


Re: How to use SEO urls in CakePHP without the ID?

2010-07-14 Thread cricket
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