[eluser]breaddes[/eluser]
This is a pretty simple HMVC app to explain my problem.
This application loads the welcome module in
site/welcome first. That's my entry point. Here I get my main content for my site and I additionally run a module called extra which gives me an extra Widgetlike content for my site.
Code:
<?php
class Welcome extends Core_Controller {
function __construct() {
parent::__construct();
}
function index() {
$this->data['content'] = '<h1>Hey</h1>
modules::run('extra');
}
}
My module extra creates a widget partial and makes it as a global string available.
Code:
<?php
class Extra extends Core_Controller {
function __construct() {
parent::__construct();
}
function index() {
$this->load->vars('widget', $this->load->view('widget', '', TRUE));
}
function new() {
$this->load->vars('widget', $this->load->view('new_widget', '', TRUE));
}
This works so far. And if I output my data in my template everything there.
Code:
<?php $this->load->view('header'); ?>
<?=$widget?>
<?=$content?>
<?php $this->load->view('footer'); ?>
Now what I want to achieve is something tricky. There is a link on the widget which should call the method new() in Extra to change the widgets view. But at the same time I don't want to leave my Welcome site, which is the corresponding current url.
If I would just call
extra/new I will loose my welcome content which will later be missed in my template. So how can I maintain the current url state and still call another widget?
The only thing I can think of is creating another method in Welcome:
Code:
function other() {
$this->data['content'] = '<h1>Hey</h1>
modules::run('extra/new');
}
That would do exactly what I want. But isn't it overhead to create two methods for every function I want to call. It would also mean that I don't have a good encapsulation of my extra module.