Welcome Guest, Not a member yet? Register   Sign In
Load a controller from a library HMVC
#1

[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 !
#2

[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 ?
#3

[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
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB