Advertisement
azmicolejr

Mengatur Default Routes di Codeigniter pada Sub Folder

Jun 29th, 2019
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2.  
  3. class MY_Router extends CI_Router {
  4.     protected function _set_default_controller() {
  5.  
  6.         if (empty($this->default_controller)) {
  7.  
  8.             show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
  9.         }
  10.         // Is the method being specified?
  11.         if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) {
  12.             $method = 'index';
  13.         }
  14.  
  15.         // This is what I added, checks if the class is a directory
  16.         if( is_dir(APPPATH.'controllers/'.$class) ) {
  17.  
  18.             // Set the class as the directory
  19.  
  20.             $this->set_directory($class);
  21.  
  22.             // $method is the class
  23.  
  24.             $class = $method;
  25.  
  26.             // Re check for slash if method has been set
  27.  
  28.             if (sscanf($method, '%[^/]/%s', $class, $method) !== 2) {
  29.                 $method = 'index';
  30.             }
  31.         }
  32.  
  33.         if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php')) {
  34.  
  35.             // This will trigger 404 later
  36.  
  37.             return;
  38.         }
  39.         $this->set_class($class);
  40.         $this->set_method($method);
  41.         // Assign routed segments, index starting from 1
  42.         $this->uri->rsegments = array(
  43.             1 => $class,
  44.             2 => $method
  45.         );
  46.         log_message('debug', 'No URI present. Default controller set.');
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement