Welcome Guest, Not a member yet? Register   Sign In
Having troubles with Loader class and HMVC
#1

[eluser]Twisted1919[/eluser]
Hi all,
My problem is that i want to rename the views folder name into templates(makes more sense for my new project) without hacking into core files.

Based on that, i thought that extending the CI_Loader class would do the trick .
So i have my MY_Loader.php:
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class MY_Loader extends CI_Loader{

public function __construct()
    {
        parent::CI_Loader ;
        $this->_ci_view_path = APPPATH.'templates/';

    }
But it just jumps over it, it doesn't load it at all.
Might this be an issue because of the HMVC library ?
Any suggestions ?
Thanks.
#2

[eluser]Twisted1919[/eluser]
Oups, my bad , seems like i should create MX_Loader.php instead of MY_Loader.php . Now it works .
Another question that i have .
Now it loads the template files from /templates instead of /views .
But if i create a templates folder in my module, the files will not be loaded, any way to fix this ?
#3

[eluser]Twisted1919[/eluser]
Me again Big Grin
My first approach was kinda wrong i think .
All i had to do :
1. On HMVC's Controller class after line 85 (the foreach loop) i added :
Code:
$this->_ci_view_path = APPPATH.'templates/';
//So it becomes
/* ci loader references */
        foreach (get_class_vars('CI_Loader') as $var => $val) {
            $this->$var =& CI::$APP->load->$var;
         }
        $this->_ci_view_path = APPPATH.'templates/';
On line 239 , in the load function i've changed to :
Code:
list($path, $view) = Modules::find($view, $this->_module, 'templates/');
//instead of
list($path, $view) = Modules::find($view, $this->_module, 'views/');

And on Modules.php on line 168 i changed to
Code:
if ($base == 'models/' OR $base == 'forms/' OR $base == 'templates/')
//instead of
if ($base == 'views/' OR $base == 'models/' OR $base == 'forms/')

Now it works perfect , maybe this will help somebody else without HMVC experience as i am Smile
#4

[eluser]wiredesignz[/eluser]
All you really need is to leave views and add an offset for load->view() to use the templates directory, something like:
Code:
$config['templates'] = '../templates/';
$templates = config_item('templates');
$this->load->view($templates.'someTemplate', $data);
#5

[eluser]Twisted1919[/eluser]
Yes , this makes sense , didn't try it yet but i am sure it will work Smile
Thanks .




Theme © iAndrew 2016 - Forum software by © MyBB