[eluser]freshface[/eluser]
Hey
I am creating a slug for my url title but i want to check if it is unque in my database.
when i have: ci-rocks and i post another title with ci-rocks it should become ci-rocks-1 but if i post another time ci-rocks it should become ci-rocks-2 and so on.
But i have a proplem with my recusion in my model.
Code:
var $counter = 0;
var $orig_slug = '';
function unique_slug($slug)
{
if($this->orig_slug == '')
{
$this->orig_slug = $slug;
}
$this->db->where('slug', $this->orig_slug);
$this->db->from('blog_blog');
$count = $this->db->count_all_results();
if((int)$count != 0)
{
$this->counter++;
$slug = $this->orig_slug . '-' . $this->counter;
$resp = $this->unique_slug($slug);
return $slug;
//var_dump($this->unique_slug($slug));
//return $slug;
//if(!$this->unique_slug($slug))
//{
// //$this->unique_slug($slug);
//
//}
//else
//{
// return $slug;
//}
//
//return FALSE;
}
else
{
return $this->orig_slug;
}
Does somebody know my mistake?