Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To use a view twice on a page, or use two different views from one controller route, call <code>$this-&gt;load-&gt;view()</code> once for each view, but passing <code>$data</code> only once. That means that all of your model data is added to a single <code>$data</code> variable, using different keys or array elements.</p> <p>Example:</p> <pre><code>$this-&gt;data = array( 'people' =&gt; $this-&gt;SomeModel-&gt;list1(), 'dogs' =&gt; $this-&gt;SomeModel-&gt;list2() ); $this-&gt;load-&gt;view('list-view', $this-&gt;data); $this-&gt;load-&gt;view('list-view'); $this-&gt;load-&gt;view('footer'); </code></pre> <p>For many of my own sites, I use a special base controller that implements a <code>view()</code> function to load each of my common page parts so that each controller route needs only to populate <code>$this-&gt;data</code> and call <code>$this-&gt;view('unique-part')</code> (as most pages will have a header, footer, sidebar, navigation bar, and then some unique view in the middle). </p> <p>Example:</p> <pre><code>function page($p, $extra) { $this-&gt;load-&gt;view('_parts/header', array_merge($this-&gt;data, $extra)); $this-&gt;load-&gt;view("$base/sidebar"); $this-&gt;load-&gt;view("$base/$p"); $this-&gt;load-&gt;view('_parts/footer'); } </code></pre> <p>Note that the header/footer are in a _parts folder, shared among other routes. CodeIgniter caches the view data so that the data will be available to any view after the first one that references it in a given route.</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