CodeIgniter Forums
HMVC get current loader inside a library ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: HMVC get current loader inside a library ? (/showthread.php?tid=59699)



HMVC get current loader inside a library ? - El Forum - 11-06-2013

[eluser]Unknown[/eluser]
Hello

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
Code:
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
Code:
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 ?


HMVC get current loader inside a library ? - El Forum - 11-06-2013

[eluser]wiredesignz[/eluser]
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.

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

Or

Code:
<!-- 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.

Code:
$this->load->view('module_name/view_name');



HMVC get current loader inside a library ? - El Forum - 11-07-2013

[eluser]Unknown[/eluser]
OK
Thanks for your answer, the third solution did the tricks