title: get unique slug in codeigniter
body: <p>I want to get unique slug for my articles. I am using codeigniter. I was wondering to have some thing like <code>sample-title-1</code> and <code>sample-title-2</code> if there are two articles that have the same title like codeignier does with file upload <code>filename(:num)</code> . I could not figure out a way to do it. I am not an expert on codeigniter. I am learning it.</p>
  
  <p>I prepared a function, when passed a string <code>$str</code> it checks if the slug exists, if it does, it adds the <code>ID</code> of that article to the end of that slug and returns it, if not, it returns the slug.</p>
  
  <p>It is working fine and serving the purpose of unique slug. But what I wanted was to have something like <code>sample-title-1</code> and <code>sample-title-2</code> . Is there any way to do so?</p>
  
  <pre><code>$data['slug'] = $this-&gt;get_slug($data['title']);
  
  
  public function get_slug ($str)
      {
          $slug = url_title($str, 'dash', true);
          // Do NOT validate if slug already exists
          // UNLESS it's the slug for the current page
  
          $id = $this-&gt;uri-&gt;segment(4);
          $this-&gt;db-&gt;where('slug', $slug);
          ! $id || $this-&gt;db-&gt;where('id !=', $id);
          $category = $this-&gt;category_m-&gt;get();
  
          if (count($category)) {
              return $slug.$id;
          }
  
          return $slug;
      }
  </code></pre>