Would it also be possible to render more controller methods of the same controller as partials, e.g. render the index method, the sidemenu method and the footer method of the same controller. I hope you understand what I mean.
This could be achieved with a little modification in the run() function:
function run($module, $data = FALSE, $config = FALSE, $method='index')
{
$this->load($module, $config);
list($class) = $this->in_subdir($module);
return $this->ci->$class->$method($data);
}
But if you use the run() function to you load your modules directly from your views, I think you don’t need to run another method. For example:
// main view:
<div id="header"><?=$this->modules->run('header_module')?></div>
<div id="contents"><?=$this->modules->run('contents_module')?></div>
<div id="footer"><?=$this->modules->run('footer_module')?></div>
// header module:
class Header_module extends HMVC {
function index() {
$this->load->view('header_view');
}
}
// contents module:
class Contents_module extends HMVC {
function index() {
$this->load->view('contents_view');
}
}
// contents view:
<div id="offers"><?=$this->modules->run('offers_module')?></div>
<div id="news"><?=$this->modules->run('news_module')?></div>
// offers module:
class Offers_module extends HMVC {
function index() {
$this->load->model('products_model','products');
$data['offers_list']=$this->products->get_offers();
$this->load->view('offers_view',$data);
}
}
// news module:
class News_module extends HMVC {
function index() {
$this->load->model('news_model','news');
$data['news_list']=$this->news->get_last_news();
$this->load->view('news_view',$data);
}
}
But… You may want to have an add(), edit() or delete() methods in your News_module to manipulate the news. To execute these functions, you need to use the _remap() function in the controller, as Wiredesignz said. Another way to do this is to create a separated controller, instead of add new functions to your module. I think is better leave the modules only to render partials, not to act as controllers. You can do it, but is more easy to work with controllers, which natively grabs the parameters from the URI, than remap the URI to your modules. By its turn, the controller that will manipulate the data can load another modules, more suited for its needs. This is more flexible and is the right thing to do in a MVC structure.