CodeIgniter Forums
Load a controller from a library HMVC - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Load a controller from a library HMVC (/showthread.php?tid=59627)



Load a controller from a library HMVC - El Forum - 10-29-2013

[eluser]vdecaux83[/eluser]
Hello everybody !

I try to develop a kind of "hook" system. I want to load in my Template library some controllers functions.

So I did this function :
Code:
function hookTop()
    {
        $output = '';
        
        foreach ($this->_ci->config->item('hookTop') as $module) {
            $this->_ci->load->module($module);
            $output .= $this->$module->hookTop();
        }
        
        return $output;
    }

And I have in my config item the list of modules containing a "hookTop" function.
But I have this error :

Quote:Fatal error: require(): Cannot redeclare class ci in /var/www/preprod/toolbox/application/third_party/MX/Controller.php on line 4

I am using HMVC module (version 5.4), and my controller extends MX_CONTROLLER.

Does anyone else have this error? Is this possible to do?
Thanks !


Load a controller from a library HMVC - El Forum - 10-30-2013

[eluser]vdecaux83[/eluser]
I really didn't find anything about my question...

There is no way to get a controller function from a library ? Is this possible to show a HTML view from a library ?


Load a controller from a library HMVC - El Forum - 10-30-2013

[eluser]vdecaux83[/eluser]
Ok I get it !
I simply use a require_once.. Not the best way I think, but it works !

Code:
$output = '';
        
        foreach ($this->_ci->config->item('hookTop') as $module) {
            require_once(APPPATH . 'modules/'. $module .'/controllers/'. $module .'.php');
            $_module = new $module();
            $output .= $_module->hookTop();
        }
        
        return $output;

In this way, I can load controller function and enable hook in my template ! Pretty smart with HMVC Smile


Load a controller from a library HMVC - El Forum - 10-31-2013

[eluser]InsiteFX[/eluser]
Code:
/*
|--------------------------------------------------------------------------
| HMVC Module Paths. - Add to the bottom of your config.php file.
|--------------------------------------------------------------------------
|
| Paths to the Modules directories.
|
*/
$config['modules_locations'] = array(
APPPATH.'modules/' => '../modules/',
);

This is in the HMVC documentation.