Welcome Guest, Not a member yet? Register   Sign In
[Closed] Can not dectect subfolders in myloader
#1

[eluser]riwakawd[/eluser]
I am trying to get it so can load controller in to parent controller but cannot seem to get extra sub-folders to pick up. Only works in first level, what is best way to make it work to pick up extra sub-folders

Sample Controller.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
    public function __construct(){
      parent::__construct();
      $this->load->controller('header');
      $this->load->controller('folder/folder/header'); // Need it to be able to pick up folder locations.
   }

    public function index() {
        $data['header'] = $this->header->index();
        $this->load->view('welcome_message', $data);
    }
}

My Loader

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Loader extends CI_Loader{

    public function __construct(){
        parent::__construct();
    }

    public function controller($file_name){
        $CI = & get_instance();

        $location = APPPATH .'controllers/'. $file_name.'.php';
        $object_name = $file_name;
        $class_name = ucfirst($file_name);

        if(file_exists($location)){
            require $location;

            $CI->$object_name = new $class_name();
        }
        else{
            show_error("Unable to load the requested controller class: ".$class_name);
        }
    }

}
#2

[eluser]riwakawd[/eluser]
I have got folders problem working ok now

My Loader

Code:
public function controller($file_path){
        $CI = & get_instance();
    
        $file_path_arr = explode('/', $file_path);
        $file_name = end($file_path_arr);
        
        $file_path = APPPATH.'controllers/'.$file_path.'.php';
        $object_name = $file_name;
        $class_name = ucfirst($file_name);
    
        if(file_exists($file_path)){
            require $file_path;
        
            $CI->$object_name = new $class_name();
        }
        else{
            show_error("Unable to load the requested controller class: ".$class_name);
        }
    }
#3

[eluser]Tpojka[/eluser]
Or you can choose:
Code:
APPPATH . 'core/MY_Router.php'
#4

[eluser]riwakawd[/eluser]
[quote author="Tpojka" date="1399300952"]Or you can choose:
Code:
APPPATH . 'core/MY_Router.php'
[/quote]

I said in previous post got it working can load extra folders.

Now just working on making it able to load multiple $data[''] = array(); only works with one array loaded the error comes up if add two or more. like unable to find object class index() is one off the errors when load second array.




Theme © iAndrew 2016 - Forum software by © MyBB