Welcome Guest, Not a member yet? Register   Sign In
HMVC loading driver across modules
#2

(This post was last modified: 04-22-2016, 10:56 AM by orionstar.)

I had this problem too, put the method below to your main driver file!
This will override the default driver loading method.

PHP Code:
public function load_driver($child)
{
    
// Get CodeIgniter instance and subclass prefix
    
$prefix config_item('subclass_prefix');

    if ( ! isset(
$this->lib_name))
    {
        
// Get library name without any prefix
        
$this->lib_name str_replace(array('CI_'$prefix), ''get_class($this));
    }

    
// The child will be prefixed with the parent lib
    
$child_name $this->lib_name.'_'.$child;

    
// See if requested child is a valid driver
    
if ( ! in_array($child$this->valid_drivers))
    {
        
// The requested driver isn't valid!
        
$msg 'Invalid driver requested: '.$child_name;
        
log_message('error'$msg);
        
show_error($msg);
    }

    
// Search the child only in the current folder...
    
$path realpath(dirname(__FILE__));

    
// Does the file exist?
    
$file $path '/drivers/' $child_name '.php';
    if (
file_exists($file))
    {
        
// Include source
        
include_once($file);
    }

    if (
class_exists($child_nameFALSE))
    {
        
$class_name $child_name;
    }
    else
    {
        
$msg 'Unable to load the requested driver: '.$class_name;
        
log_message('error'$msg);
        
show_error($msg);
    }

    
// Instantiate, decorate and add child
    
$obj = new $class_name();
    
$obj->decorate($this);
    
$this->$child $obj;
    return 
$this->$child;

Reply


Messages In This Thread
HMVC loading driver across modules - by reanvdm - 04-22-2016, 08:19 AM
RE: HMVC loading driver across modules - by orionstar - 04-22-2016, 10:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB