• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Modular Extensions and Template library

#1
[eluser]Rudybg[/eluser]
Hi.
I use Modular Extensions HMVC and Template library by Phil Sturgeon.
How can I use $this->template in a module's controller. I want to load some module's javascript files in the head of the html layout with the append_metadata() method.

An example in order of execution:
controllers/home/home.php - the main controller
Code:
class Home extends MX_Controller {

    function index()
    {
        $this->template->build('login');
    }

}

views\layouts\default.php- the default layout
Code:
<html>
    <head>
        <?php include "\..\partials\head.php"; ?>
    </head>
    <body>
           //calling topbar module
        <?php echo Modules::run('navigation_panels/TopBar/render'); ?>
        <?php echo $template['body']; ?>
    </body>
</html>

modules\navigation_panels\controllers\TopBar.php- the topbar module's controller
Code:
class TopBar extends MX_Controller {

    public function __construct()
    {
        parent::__construct();
//want to manipulate the head but template property is not visible
     $this->template->prepend_metadata(generateJavaScriptIncludeTag('TOPBAR_JAVASCRIPT_LOCATION' . 'change_language.js'));
    }

    public function render()
    {
        $data['languages'] = $this->language->getOtherLanguageArray();
        $this->load->view('TopBar_view', $data);
    }
}


#2
[eluser]PhilTem[/eluser]
Just don't put it in the __construct() but in the method called - in your case the 'render'-method. I think that should be it.

#3
[eluser]Rudybg[/eluser]
Isn't working. It only works when i call prepend_metadata() just before the build() method. By the way i checked with method_exists($this->template,'prepend_metadata') -> returns TRUE. But when i call it - no results;

#4
[eluser]Rudybg[/eluser]
Did i understand the HMVC conception. My idea is to use the application/controllers to reach the website from url and these controllers to load layouts, use modules and to append the modules to the layouts. The module views will be only parts - example container with main menu, top bar, profile. Is that right?

#5
[eluser]Rudybg[/eluser]
OK. The problem is that I use two different successors of MX_Controller and they have two different instances of template in $this->template. What should I do?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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