title: Codeigniter Dynamic Routing from database
body: <p>I have implemented a dynamic routing system to my Codeigniter from the database. while am loading the routes dynamically it is showing me an internal server error 500. I have already implemented in my other projects also but it's not possible here. I am using Codeigniter <a href="https://github.com/chriskacerguis/codeigniter-restserver" rel="nofollow noreferrer">https://github.com/chriskacerguis/codeigniter-restserver</a></p>
  
  <pre><code>// $route['default_controller'] = 'Home';
  // $route['person/(:any)'] = 'Home/person_data/$1';
  // $route['filmography/(:any)'] = 'Home/filmo_details/$1';
  // $route['biography/(:any)'] = 'Home/bio_details/$1';
  // $route['article/(:any)'] = 'Home/article_details/$1';
  // $route['jukebox/(:any)'] = 'Home/jukebox/_details/$1';
  // $route['admin'] = 'Admin';
  // $route['login'] = 'Admin/login';
  // $route['404_override'] = '';
  // $route['translate_uri_dashes'] = TRUE;
  
  $route[ 'default_controller' ]  = 'Home';
  $route['admin'] = 'Admin';
  $route['login'] = 'Admin/login';
  $route[ '404_override' ]        = 'my404';
  
  require_once(BASEPATH .'database/DB'. EXT);
  $db =&amp; DB();
  $query = $db-&gt;get( '_app_routes' );
  $result = $query-&gt;result();
  // echo"&lt;pre&gt;";print_r($result);exit;
  foreach( $result as $row )
  {
      $route[ $row-&gt;slug ]                 = $row-&gt;controller;
      $route[ $row-&gt;slug.'/:any' ]         = $row-&gt;controller;
      $route[ $row-&gt;controller ]           = $row-&gt;controller;
      $route[ $row-&gt;controller.'/:any' ]   = $row-&gt;controller;
  }
  $route['translate_uri_dashes'] = TRUE;
  
  
  
  /*
  | -------------------------------------------------------------------------
  | Sample REST API Routes
  | -------------------------------------------------------------------------
  */
  $route['api/example/users/(:num)'] = 'api/example/users/id/$1'; // Example 4
  $route['api/example/users/(:num)(\.)([a-zA-Z0-9_-]+)(.*)'] = 'api/example/users/id/$1/format/$3$4'; // Example 8
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function person_details($personid){
          $data = array();
          $data['persondata']=$this-&gt;User_model-&gt;getPersondata($personid);
          // echo"&lt;pre&gt;";print_r($data);exit;
          $this-&gt;load-&gt;view('default/person_details_view',$data);
      }
  </code></pre>
  
  <p><strong>Routes generated</strong></p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [ID] =&gt; 1
              [slug] =&gt; pawan-kalyan
              [controller] =&gt; Home/person_details/1
              [PAGE_ID] =&gt; 1
              [PAGE_GROUP_ID] =&gt; 1
              [STATUS] =&gt; 1001
          )
  
      [1] =&gt; stdClass Object
          (
              [ID] =&gt; 2
              [slug] =&gt; chiranjeevi
              [controller] =&gt; Home/person_details/2
              [PAGE_ID] =&gt; 2
              [PAGE_GROUP_ID] =&gt; 1
              [STATUS] =&gt; 1001
          )
  
      [2] =&gt; stdClass Object
          (
              [ID] =&gt; 3
              [slug] =&gt; nagababu
              [controller] =&gt; Home/person_details/3
              [PAGE_ID] =&gt; 3
              [PAGE_GROUP_ID] =&gt; 1
              [STATUS] =&gt; 1001
          )
  
      [3] =&gt; stdClass Object
          (
              [ID] =&gt; 4
              [slug] =&gt; allu-arjun
              [controller] =&gt; Home/person_details/4
              [PAGE_ID] =&gt; 4
              [PAGE_GROUP_ID] =&gt; 1
              [STATUS] =&gt; 1001
          )
  
      [4] =&gt; stdClass Object
          (
              [ID] =&gt; 5
              [slug] =&gt; ram-charan-tej
              [controller] =&gt; Home/person_details/5
              [PAGE_ID] =&gt; 5
              [PAGE_GROUP_ID] =&gt; 1
              [STATUS] =&gt; 1001
          )
  
      [5] =&gt; stdClass Object
          (
              [ID] =&gt; 6
              [slug] =&gt; sai-dharam-tej
              [controller] =&gt; Home/person_details/6
              [PAGE_ID] =&gt; 6
              [PAGE_GROUP_ID] =&gt; 1
              [STATUS] =&gt; 1001
          )
  
      [6] =&gt; stdClass Object
          (
              [ID] =&gt; 7
              [slug] =&gt; varun-tej
              [controller] =&gt; Home/person_details/7
              [PAGE_ID] =&gt; 7
              [PAGE_GROUP_ID] =&gt; 1
              [STATUS] =&gt; 1001
          )
  
      [7] =&gt; stdClass Object
          (
              [ID] =&gt; 8
              [slug] =&gt; naga-babu-says-i-don't-know-balakrishna
              [controller] =&gt; Home/article_details/1
              [PAGE_ID] =&gt; 8
              [PAGE_GROUP_ID] =&gt; 1
              [STATUS] =&gt; 1001
          )
  
  )
  </code></pre>