I my project I need to create model without CI instance.
I use function load_class.
If file_exists($path.$directory.'/'.$class.'.php') in the applications/models directory then the $name variable is set to $name = 'CI_'.$class; and check for new class name.
And the $name variable's value won't changes to $class if CI.$class does not exist.
After that the system tries to load not existed class with name CI.$class instead of existed class $class.
Is this bug or I don't undestand logic of this function?
I use the latest version of CI 3.x.
I use function load_class.
PHP Code:
function &load_class($class, $directory = 'libraries', $param = NULL)
{
static $_classes = array();
// Does the class exist? If so, we're done...
if (isset($_classes[$class]))
{
return $_classes[$class];
}
$name = FALSE;
// Look for the class first in the local application/libraries folder
// then in the native system/libraries folder
foreach (array(APPPATH, BASEPATH) as $path)
{
if (file_exists($path.$directory.'/'.$class.'.php'))
{
$name = 'CI_'.$class;
if (class_exists($name, FALSE) === FALSE)
{
require_once($path.$directory.'/'.$class.'.php');
}
break;
}
}
// Is the request a class extension? If so we load it too
if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
{
$name = config_item('subclass_prefix').$class;
if (class_exists($name, FALSE) === FALSE)
{
require_once(APPPATH.$directory.'/'.$name.'.php');
}
}
// Did we find the class?
if ($name === FALSE)
{
// Note: We use exit() rather than show_error() in order to avoid a
// self-referencing loop with the Exceptions class
set_status_header(503);
echo 'Unable to locate the specified class: '.$class.'.php';
exit(5); // EXIT_UNK_CLASS
}
// Keep track of what we just loaded
is_loaded($class);
$_classes[$class] = isset($param)
? new $name($param)
: new $name();
return $_classes[$class];
}
If file_exists($path.$directory.'/'.$class.'.php') in the applications/models directory then the $name variable is set to $name = 'CI_'.$class; and check for new class name.
And the $name variable's value won't changes to $class if CI.$class does not exist.
After that the system tries to load not existed class with name CI.$class instead of existed class $class.
Is this bug or I don't undestand logic of this function?
I use the latest version of CI 3.x.