If we put model classes in other folders (rather than default application\models),
assume the model class is ThisModel, and put it into \AAA\BBB\CCC folder.
1. in application\config\autoload.php, add following line:
spl_autoload_register(array(‘MY_Loader’, ‘load_gas_orm_model’));
2. then in application/core/MY_Loader.php, add the following method:
public static function load_gas_orm_model($class)
{
$arr = explode(’\\’, strtolower($class));
$path = ‘path/to/parent/folder/’. strtolower($class) . ‘.php’;
$path = str_replace(’\\’,’/’, $path);
if (file_exists($path)) {
require_once $path;
}
}
3. in model class:
<?php
namespace AAA\BBB\CCC; //AAA, BBB, CCC is mapping to our folder structure
class ThisModel extends ORM{
}
4. in controller class:
<?php
use AAA\BBB\CCC\ThisModel;
class ThisController extends CI_Controller{
function this_action()
{
$record = ThisModel::find(1);
..............
}
}