Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I know that this topic is over a year old, however I have been Googling to gain some more insight into the structure an HMVC program should take, and how it can be implemented in CI, and have not found very many answers.</p> <p>I'm pretty sure that for HMVC to work properly, with several widgets incorporated on all pages of a site, they need to be orchestrated by one main controller. This will be the top level of the heirarchy. Let me try to give an example:</p> <p>You have a site with a shopping cart widget on every page. When you wish to use the cart functionality, you will need to link to methods in the cart module, e.g.:</p> <pre><code>&lt;a href="cart/add/&lt;?=$item?&gt;"&gt;add&lt;/a&gt; </code></pre> <p>The problem using this link is that you do not want to reload the rest of the site from that module. Instead, you can route the link through your main controller and have it reload the module, calling the desired method. e.g.</p> <pre><code>&lt;a href="site_controller/cart_add/&lt;?=$item?&gt;"&gt;add&lt;/a&gt; </code></pre> <p>Then in the site controller, it will simply pass the method call to the main view</p> <pre><code>&lt;?php function cart_add($item){ $data['cart'] = 'cart/add/'.$item; $this-&gt;load-&gt;view('main', $data); } ?&gt; </code></pre> <p>The view will call the cart widget with the following:</p> <pre><code>&lt;?php echo modules::run($cart); ?&gt; </code></pre> <p>Obviously this is a simplified explanation, and the main site controller will be handling several widgets in one main view, so passing the correct data will need to be managed better than just calling the main view from within a method. But hopefully this gives an idea of the structure I am referring to.</p> <p>If anyone reads this and thinks I'm wrong, I would love to hear other solutions people have found to this issue.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload