[eluser]developer10[/eluser]
I've just remembered an idea that came to my mind earlier today.
Colin's Template.php has functions like this:
Code:
function set_master_template($filename)
and HMVC author @wiredesignz suggested using this for getting current module name:
Code:
$this->router->fetch_module();
The thing is I'm not able to fetch module in Template.php where I actually need it.
So I was thinking, what if I fetch module name first and then pass it as an extra parameter to each function?
Something like this:
Code:
// this is controller
$currmodule = $this->router->fetch_module();
$this->template->write('title', 'auth hmvc!', $currmodule);
$this->template->write_view('content', 'login_form', $data, $currmodule);
$this->template->render();
Then in Template.php I would use that value as a replacement for module name, like in:
Code:
function write_view($region, $view, $data = NULL, $overwrite = FALSE, $currmodule)
{
$args = func_get_args();
// Get rid of non-views
unset($args[0], $args[2], $args[3]);
// Do we have more view suggestions?
if (count($args) > 1)
{
foreach ($args as $suggestion)
{
if (file_exists(APPPATH .'modules/'.$modulename.'/views/'. $suggestion . EXT) or file_exists(APPPATH .'modules/'.$modulename.'/views/'. $suggestion))
{
// Just change the $view arg so the rest of our method works as normal
$view = $suggestion;
break;
}
}
}
$content = $this->CI->load->view($view, $data, TRUE);
$this->write($region, $content, $overwrite);
}
I don't know if this approach would work but I feel this must be close to the final solution. My suggestion goes for @Colin to add support for HMVC in a manner that is similar to this because I believe many people would like to use his library with HMVC!