Codeigniter – A Master Layout

In this screencast, we’ll explore a few different techniques to DRY up your codeigniter views by implementing a master layout file for your site. Here’s a quick start if you’d like to setup your own master model.

<!DOCTYPE html>
    <title><?php echo isset($title) ? "PHP Sandbox: $title" : NULL; ?></title>
    <link rel="stylesheet" href="/assets/css/site.css" type="text/css" />
    <?php $this->load->view('layout/navigation'); ?>
    <div class="container">
      <?php $this->load->view($content); ?>
    <script type="text/javascript" src="/assets/js/site.js"></script>

Assuming you’ve configured your default layout within core/MY_Controller.php

class MY_Controller extends CI_Controller {

  public $layout;

  public function __construct()
    $this->layout = 'layout/master';

… you would call the master layout from your views like this:

$data['title'] = $product->name;
$data['content'] = 'products/show';
$this->load->view($this->layout, $data);

4 thoughts on “Codeigniter – A Master Layout

  1. I enjoyed watching your codeigniter screencasts.
    Very informative. Thank you. Lookin’ forward to #3 🙂
    Would you be so kind to share the source code used in the tuts?
    To fully understand I would like a closer look.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s