This is a primitive java like import for CI.
[b]CAUTION [/b]: It may produce unpredictable result If you have two class with the same name (even if you put it in a different file/package).
You must enable hooks first at yout config.php [code] $config['enable_hooks'] = TRUE; [/code]
Add a hooks configuration at hooks.php [code] $hook['pre_system'] = array( 'class' => '', 'function' => 'fake', 'filename' => 'ClassLoader.php', 'filepath' => 'hooks' ); [/code]
Create ClassLoader.php under hooks directory [code]
function import($class, $package = 'package') { $class = $package . "/" . $class; $class = str_replace(".", "/", $class); $path = APPPATH . $class . EXT;
if(file_exists($path)){ require_once($path); return true; }else{ return false; }
} ?> [/code]
Create a folder named 'package' under application directory. This directory is the home for your own class.
Example: We create a class BaseController on package/com/company/project/controller/BaseController.php
[code]
function BaseController(){ parent::Controller(); }
}
?> [/code]
At your regular controller you can import base controller like this: [code]
import('com.company.project.controller.BaseController'); // you can import other class here
class Homepage extends BaseController{
function Homepage(){ parent::BaseController(); } function index(){ echo "test"; }
There was an error while loading. Please reload this page.