Advertisement
Guest User

CI slug

a guest
Jun 17th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. class Slug {
  4.      
  5.     public function create_slug($slug, $table)
  6.     {  
  7.         $CI =& get_instance();
  8.         $CI->load->helper('url');
  9.         $CI->load->helper('text');
  10.         $CI->load->database();
  11.  
  12.         $slug = strtolower(url_title(convert_accented_characters($slug)));
  13.        
  14.         $query = $CI->db->query("SELECT * FROM $table WHERE slug = '$slug'");
  15.         $count = $query->num_rows();
  16.        
  17.         if ($count == 1 ) {
  18.                
  19.                 do
  20.                 {
  21.                 $count++;
  22.                 $slug .= '-'.$count;
  23.                 }  while ($count == 0);
  24.  
  25.        }
  26.              
  27.         return $slug;
  28.      
  29.     }
  30.  
  31. }  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement