• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HMVC get current loader inside a library ?


I am trying to integrate the wonderful HMVC library into my code igniter 2 application but i have some trouble to use a custom layout library inside hmvc modules .

Each time i want to load a view located outside the module view folder i get the unable to load file error .

here's an example of the problem :

here's a module controller
class User extends MX_Controller {
public function register() {
                $viewData['captcha'] =  $this->load->module('captcha/captcha');

                 //generate a file not found error
                return $this->layout->partialView('register.php', $viewData);

here's my layout library
class Layout
    private $_ci = NULL;
    private $_var = array();
    public function __construct()
        $this->_ci = & get_instance();
        $this->_var['output'] = '';
    public function partialView($name, $data=array())
     $this->_var['output'] = $this->_ci->load->view($name, $data, false);
         //wrap the result inside a custom view
     $this->_ci->_load->view('layout/default/partial.php', $this->_var);

When i try to load the view using mx_loader inside my layout library it seems that that the reference stored inside $this->_ci->load is set to the mx loader of the captcha module and not the user module . Can you show me a way to get the current loader instance inside my library ?

When using the "$this->load->module()" method the CI instance will refer to the most recently loaded controller.

If you wish to use a controller as a view partial you should use the "Modules::load()" method from within your page controller to load the controller object into a local variable or use the "Modules::run()" method from within your view to load and return your partial.

//load the module controller to a local variable
$viewData['captcha'] = Modules::load('captcha');


<!-- Run the module controller from within the view -->
<?php echo Modules::run('captcha', $data); ?>

Alternatively you can specify the name of the module that you wish to load the view from if you have loaded a new controller and changed the CI super object instance.


Thanks for your answer, the third solution did the tricks

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.