[eluser]xwero[/eluser]
Because you can autoload models now a models directory in the system directory would be a welcome addition for this sort of thing.
For the time being you can extend the loader library to work with a models directory in the system directory. I've added the possibility to extend the model like you would do for the libraries with the prefix in the config.
Code:
class MY_Loader extends CI_Loader
{
function MY_Loader()
{
parent::CI_Loader();
}
function model($model, $name = '', $db_conn = FALSE)
{
if (is_array($model))
{
foreach($model as $babe)
{
$this->model($babe);
}
return;
}
if ($model == '')
{
return;
}
// Is the model in a sub-folder? If so, parse out the filename and path.
if (strpos($model, '/') === FALSE)
{
$path = '';
}
else
{
$x = explode('/', $model);
$model = end($x);
unset($x[count($x)-1]);
$path = implode('/', $x).'/';
}
if ($name == '')
{
$name = $model;
}
if (in_array($name, $this->_ci_models, TRUE))
{
return;
}
$CI =& get_instance();
if (isset($CI->$name))
{
show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
}
$model = strtolower($model);
$system_model = FALSE;
if (file_exists(BASEPATH.'models/'.$path.$model.EXT))
{
$basepath_model = TRUE;
}
$application_model = FALSE;
if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT))
{
show_error('Unable to locate the model you have specified: '.$model);
}
else
{
$application_model = $path.$model;
}
if($application_model === FALSE && file_exists(BASEPATH.'models/'.$path.config_item('subclass_prefix').$model.EXT))
{
$application_model = $path.config_item('subclass_prefix').$model;
}
if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
{
if ($db_conn === TRUE)
$db_conn = '';
$CI->load->database($db_conn, FALSE, TRUE);
}
if ( ! class_exists('Model'))
{
load_class('Model', FALSE);
}
if($system_model === TRUE)
{
require_once(BASEPATH.'models/'.$path.$model.EXT);
}
if(is_string($application_model))
{
require_once(APPPATH.'models/'.$application_model.EXT);
}
$model = ucfirst($model);
$CI->$name = new $model();
$CI->$name->_assign_libraries();
$this->_ci_models[] = $name;
}
}
The code is untested.