Welcome Guest, Not a member yet? Register   Sign In
Router
#7

(This post was last modified: 09-21-2016, 05:41 PM by wolfgang1983.)

If you need to use subfolder in CI3 for default_controller you need to have a Custom MY_Router.php

core/MY_Router.php

Link https://github.com/wolfgang1983/CI3-defa...sub_folder

controllers / pages / Welcome.php


Code:
$route['default_controller'] = 'pages/welcome';


PHP Code:
<?php
 
class MY_Router extends CI_Router {
 
   protected function _set_default_controller() {
 
        
        if 
(empty($this->default_controller)) {
 
           
            show_error
('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
 
       }
 
       // Is the method being specified?
 
       if (sscanf($this->default_controller'%[^/]/%s'$class$method) !== 2) {
 
           $method 'index';
 
       }
 
        
        
// This is what I added, checks if the class is a directory
 
       ifis_dir(APPPATH.'controllers/'.$class) ) {
 
            
            
// Set the class as the directory
 
           
            $this
->set_directory($class);
 
           
            
// $method is the class
 
           
            $class 
$method;
 
           
            
// Re check for slash if method has been set
 
           
            if 
(sscanf($method'%[^/]/%s'$class$method) !== 2) {
 
               $method 'index';
 
           }
 
       }
 
        
        if 
( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php')) {
 
           
            
// This will trigger 404 later
 
           
            return
;
 
       }
 
       $this->set_class($class);
 
       $this->set_method($method);
 
       // Assign routed segments, index starting from 1
 
       $this->uri->rsegments = array(
 
           1 => $class,
 
           2 => $method
        
);
 
       log_message('debug''No URI present. Default controller set.');
 
   }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
Router - by Ljubin - 09-21-2016, 10:09 AM
RE: Router - by cartalot - 09-21-2016, 11:15 AM
RE: Router - by Ljubin - 09-21-2016, 01:31 PM
RE: Router - by InsiteFX - 09-21-2016, 11:40 AM
RE: Router - by Ljubin - 09-21-2016, 01:44 PM
RE: Router - by cartalot - 09-21-2016, 02:35 PM
RE: Router - by wolfgang1983 - 09-21-2016, 05:40 PM
RE: Router - by Ljubin - 09-23-2016, 01:35 PM
RE: Router - by wolfgang1983 - 09-23-2016, 04:26 PM
RE: Router - by Ljubin - 09-24-2016, 02:27 AM
RE: Router - by mwhitney - 09-26-2016, 01:36 PM
RE: Router - by InsiteFX - 09-23-2016, 02:37 PM
RE: Router - by InsiteFX - 09-27-2016, 04:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB