article title to url slug with cakephp

If you are using cakephp framework for your web application development. Sometimes you need to create SEO friendly url slug from your article / post / page / news etc title.

If a article title is “Article title to url slug with cakephp” then your SEO friendly url slug supposed to be “article-title-to-url-slug-with-cakephp”

To create this kinds of url slug from a string you can use cakephp core utility class Inflector, The Inflector takes a string and manipulate it to handle some common words variations.

To make slug from string using Inflector you can use below written code in your controller:

< ?php

$str = 'Article title to url slug with cakephp';

// Converting string into slug with separator 
$str = Inflector::slug($str,'-');

$str = strtolower($str); //article-title-to-url-slug-with-cakephp

?>

For your multiple use you can create a common method on your application controller like
Read More