CodeIgniter Forums
Template was duplicated when using modules::run() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Template was duplicated when using modules::run() (/showthread.php?tid=57558)



Template was duplicated when using modules::run() - El Forum - 03-22-2013

[eluser]kakallatt[/eluser]
I build a CMS based on Codeigniter but I have a problems when I use Modular Extensions - HMVC


I have 2 controllers:

-Controller modules/blog/page:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends Frontend_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->_data['title'] = 'Homepage | ' . config_item('site_name');

        // Parser data
        $this->template->parse_view('content', config_item('template') . '/home', $this->_data);

        // Render template
        $this->template->render();
    }

    public function _getPages() {
        $this->load->model('blog/page_m');
        $pages = $this->page_m->get();

        return count($pages) ? $pages : array();
    }
}

-Controller modules/blog/home:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends Frontend_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->_data['title'] = 'Homepage | ' . config_item('site_name');

        // Parser data
        $this->template->write_view('content', config_item('template') . '/home', $this->_data);

        // Render template
        $this->template->render();
    }
}

In my views, I have:
Code:
<?php $pages = modules::run('blog/page/_getPages'); ?>
<?php foreach ($pages as $page) : ?>
          <li><a href="&lt;?php echo $page-&gt;slug; ?&gt;">&lt;?php echo $page->title; ?&gt;</a></li>
&lt;?php endforeach; ?&gt;

When I run: http://mysite.com/cms/blog/page. It's OK.
But I run: http://mysite.com/cms/blog/home. Template was duplicated (has 2 headers and 2 footers).

Please help me, thank you very much!
P/s: I use Template Library for CodeIgniter for my project