title: How to overwrite Codeigniter 3 route to show just name instead id and name
body: <p><br>
  I need a little guidance here. I'm using Codeigniter 3.
  Since it is MVC fw with segment routing,  I want to know how is possible to create custom route which will show just a <code>name</code> of record (it can be category, product, post etc..) returned from database instead of <code>id/name</code> when I need <code>id segment</code> to identify which record from database I need to return or preview by that <code>id</code>.</p>
  
  <p>I will post some code example:</p>
  
  <p>Controller</p>
  
  <pre><code>class Categories extends CI_Controller
  {
      function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;model('CategoryM');
      }
  
      public function index(){
          $data = array(
              'category_list' =&gt; $this-&gt;CategoryM-&gt;listAll()
              );
  
          $this-&gt;load-&gt;view('test/category_list', $data);
      }
  
      public function preview()
      {
          $categoryId = $this-&gt;uri-&gt;segment(2);
  
          $data = array (
              'previewByCategory' =&gt; $this-&gt;CategoryM-&gt;previewByCategory($categoryId)
              );
  
          $this-&gt;load-&gt;view('public/preview_by_category', $data);
      }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>&lt;?php
  
      class CategoryM extends CI_Model {
  
          public function listAll() {
  
              $query = $this-&gt;db
              -&gt;select('*') 
              -&gt;from('categories') 
              -&gt;where('parentid', NULL, TRUE)
              -&gt;order_by('name', 'asc') 
              -&gt;get();
  
              if($query-&gt;num_rows() &gt; 0) {
                  return $query-&gt;result();
              }else{
                  return false;
              }
  
              public function previewByCategory($categoryId=''){
  
                  $query = $this-&gt;db
                  -&gt;select( /* posts and categories data */ )
                  -&gt;from('categories')
                  -&gt;join('posts', 'posts.categoryID = categories.id', 'left')
                  -&gt;where('categories.id', $categoryId)
                  -&gt;get();
                  if( $query-&gt;num_rows() &gt; 0 ){
                      return $query-&gt;result();
                  }else{
                      return false;
                  }
              }
  
          }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>&lt;?php if($category_list):?&gt;
      &lt;?php foreach($category_list as $category):?&gt;
          &lt;h3&gt; 
              &lt;a href="&lt;?php echo base_url() . strtolower(url_title($category-&gt;name) . '/' . $category-&gt;id);?&gt;"&gt;
                  &lt;?php echo $category-&gt;name;?&gt;
              &lt;/a&gt;
          &lt;/h3&gt;
      &lt;?php endforeach;?&gt;
  &lt;?php endif;?&gt;
  </code></pre>
  
  <p>My Routes</p>
  
  <pre><code>// Category routes
  $route['categories'] = 'categories/index';
  $route['(:any)/(:num)'] = 'categories/preview/$1';
  </code></pre>
  
  <p>What I want is instead of routes </p>
  
  <pre><code>www.mywebsite/categoryname/categoryid/
  </code></pre>
  
  <p>to display just </p>
  
  <pre><code>www.mywebsite/categoryname
  </code></pre>
  
  <p>which will list all products from that category group. But how to do this without id in url. I'm sorry if my question is too broad. Thank's in advance. </p>