Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>CodeIgniter favours including the view parts of your pages sequentially from your controller functions. In the past, I've added my own baseclass to CI that implements a set of custom view functions:</p> <ul> <li><code>show($tab, $body, $data)</code> - display a view using header/body/sidebar/footer parts. Sidebar and body are pulled from the current <code>$tab</code> view folder.</li> <li><code>_print($tab, $body, $data)</code> - a <code>show();</code> variant for printing (sets up CSS, removes parts not needed for print). This could be done with CSS alone, but I've had clients needing special server-side mojo for printing.</li> <li><code>widget($type, $id)</code> - send a view chunk (generally for js/Ajax)</li> <li><code>api($type, $template)</code> - send API data by type (JSON, XML, etc.).</li> </ul> <p>This approach has worked well for a number of larger projects, but there are other ways. CodeIgniter's fork Kohana, for example, inverts the pattern, and places the page composition logic in <em>templates</em>. These templates perform the function of the base controller in a more natural way, so instead of multiple controller functions for different types of pages, you use different templates. The result is a set of view files like:</p> <ul> <li><code>app/main-template.php</code></li> <li><code>app/login-template.php</code></li> <li><code>app/print-template.php</code></li> <li><code>app/reports/wide-template.php</code></li> <li><code>widgets/control-template.php</code></li> <li><code>api/soap-template.php</code></li> <li>and so on.</li> </ul> <p>The Kohana approach can be applied to CodeIgniter as well, and is more common in other frameworks (like Rails, Cake, Zend, etc.).</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