Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's bad practice to call views inside of other views. This could be a form of controller view mixing. The view function in CI allows you to pass a third parameter that causes it to return that views output as a string. You can use this to create a compound view.</p> <p>For example:</p> <pre><code>class Page extends Controller { function index() { $data['page_title'] = 'Your title'; $this-&gt;load-&gt;view('default_layout', array( 'header' =&gt; $this-&gt;load-&gt;view('header' , array(), true), 'menu' =&gt; $this-&gt;load-&gt;view('menu' , array(), true), 'content' =&gt; $this-&gt;load-&gt;view('content', $data , true), 'footer' =&gt; $this-&gt;load-&gt;view('footer' , array(), true), )); } } </code></pre> <p>default_layout.php</p> <pre><code>&lt;? echo $header, $menu, $content, $footer; ?&gt; </code></pre> <p>You may want to combine your header and footer to make a template like this. </p> <pre><code>class Page extends Controller { function index() { $data['page_title'] = 'Your title'; $this-&gt;load-&gt;view('default_template', array( 'menu' =&gt; $this-&gt;load-&gt;view('menu' , array(), true), 'content' =&gt; $this-&gt;load-&gt;view('content', $data , true), )); } } </code></pre> <p>default_template.php</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;span&gt;Some Header HTML&lt;/span&gt; // this is your header html &lt;? echo $menu, $content; ?&gt; &lt;span&gt;some footer HTML&lt;/span&gt;&lt;/body&gt;&lt;/html&gt; // this is your footer html </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