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

Have the following (simplified) setup:



Am attempting to use Queue driver library inside of Test controller - ie across modules.
The basic load of driver library works, but the driver library is unable to find/load its child drivers/drivername.

This works in Test.php if Queue::add is a stub (ie not doing anything)

PHP Code:
function test()
$this->queue->add('test message');

But, when the library then tries to load an individual driver (e.g. to add an item into a queue), the load fails: (in Queue/Queue.php)

PHP Code:
function add($payload='')
//...ignore code that picks which driver to use - assume its queue_a
$this->queue_a->add_message($payload); //this fails, Queue_a.php cannot be found to load

The problem seems to be that HMVC overrides the core Loader.php file - but the code in core/libraries/Driver.php that locates individual driver child classes is not HMVC aware, and does not use the Loader class.

My first thought for solution is to extend core/libraries/Driver.php in new file MX_Driver.php:

PHP Code:
public function __get($child)
   //establish path of child driver     
$lib_name get_class($this);
   $reflector = new ReflectionClass($lib_name);
   $class_path  dirname($reflector->getFileName());
   $lib_path dirname($class_path);
   $module_path dirname($lib_path);

//temp add the path for CI loader to find
   // Try to load the driver
   return $this->load_driver($child);
   // Reset things to clean up

Have a feeling this has been solved before however?

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

Theme © iAndrew 2016 - Forum software by © MyBB