Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think that the solution is easier than you think.</p> <p>If now you're doing something like this in your helper:</p> <pre><code>create_menu() { $menu_items = $this-&gt;db-&gt;query('')-&gt;result(); // creating the menu here } </code></pre> <p>You could just change the function to accept input like this and still follow the MVC pattern.</p> <p><strong>Helper</strong></p> <pre><code>create_menu($input) { $menu_items = $input; // creating the menu here } </code></pre> <p><strong>Model:</strong></p> <pre><code>get_menu_data() { $menu_items = $this-&gt;db-&gt;query('')-&gt;result(); } </code></pre> <p>Does this make sense?</p> <p><strong>Edit:</strong></p> <p>This is the way I did it on one of the projects:</p> <p>I extended my standard controller. Within the constructor of that controller I called the model and grabbed the data:</p> <pre><code>$this-&gt;menu_items = $this-&gt;some_model-&gt;get_menu_items(); </code></pre> <p>Within a view <code>nav.php</code>:</p> <pre><code>if(!empty($this-&gt;subnav_item)) { // Generate menu } </code></pre> <p>This way the MVC is intact, but I dont have to worry about passing variables.</p> <p><strong>EDIT 2</strong></p> <p><strong>How to extend the standard controller:</strong></p> <p>Create a file <code>MY_Controller.php</code> in <code>application/core</code></p> <p> <pre><code>class MY_Controller extends CI_Controller { public $menu_items = ''; function __construct() { parent::__construct(); $this-&gt;load-&gt;model('some_model_that_you_always_use'); $this-&gt;load-&gt;library('some_library_that_you_always_use'); $this-&gt;menu_items = $this-&gt;some_model-&gt;get_menu_items(); } } </code></pre> <p>When you create a new controller, you extend <code>MY_Controller</code> instead of <code>CI_Controller</code> like this:</p> <pre><code> class Something extends MY_Controller { } </code></pre>
 

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