Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1.  protected function _set_default_controller() {
  2.  
  3.         if (empty($this->default_controller)) {
  4.  
  5.             show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
  6.         }
  7.         // Is the method being specified?
  8.         if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) {
  9.             $method = 'index';
  10.         }
  11.  
  12.         //disini cek terlebih dahulu controller yang dilempar sama router itu direktori atau bukan
  13.         //cth login/auth dia cek apakah login itu merupakan direktori di folder controllersnya
  14.         if( is_dir(APPPATH.'controllers/'.$class) ) {
  15.  
  16.             //kalo login tadi merupakan folder disini kita set login tersebut sebagai direktori
  17.  
  18.             $this->set_directory($class);
  19.  
  20.             //dan method dari yang hasil lemparan router tadi kita jadikan class
  21.  
  22.             $class = $method;
  23.  
  24.             //lalu kita cek ulang apakah method ini masih merupakan folder atau bukan
  25.             //karena disini saya cuman butuh 1 folder jadi disini saya asumsikan hanya bisa didalam 1 folder saja
  26.             //dan kalo auth itu memang class maka kita buat method dengan nama index
  27.            
  28.  
  29.             if (sscanf($method, '%[^/]/%s', $class, $method) !== 2) {
  30.                 $method = 'index';
  31.             }
  32.         }
  33.  
  34.         if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php')) {
  35.  
  36.             // This will trigger 404 later
  37.  
  38.             return;
  39.         }
  40.         $this->set_class($class);
  41.         $this->set_method($method);
  42.         // Assign routed segments, index starting from 1
  43.         $this->uri->rsegments = array(
  44.             1 => $class,
  45.             2 => $method
  46.         );
  47.         log_message('debug', 'No URI present. Default controller set.');
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement