Friday, June 8, 2012

Codeigniter template structure

class Pages extends CI_Controller {

  public function view($page = 'home') {

    if (!file_exists('application/views/pages/' . $page . '.php')) {
      // Whoops, we don't have a page for that!
      show_404();
    }

    $data['title'] = ucfirst($page); // Capitalize the first letter

    $data['header'] = $this->load->view('templates/header', $data, true);
    $data['body'] = $this->load->view('pages/' . $page, $data, true);
    $data['footer'] = $this->load->view('templates/footer', $data, true);

    $this->load->view('templates/page', $data);
  }

}

 ---------------------------------------------------------------------------------------------------------


And my page.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<?php echo $this->config->item('base_url') ?>public/" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>CONTINUOUS IMPRESSION</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
  </head>

  <body>
    <div id="container">
      <div class="main-wrapper">

        <div class="header-wrapper">
          <?php echo $header; ?>
        </div>

        <div class="content-wrapper">

          <div class="content"><?php echo $body; ?></div>

          <div class="footer">
            <?php echo $footer; ?>
          </div>
         
        </div>
      </div>
    </div>
  </body>
</html>

No comments: