Tuesday, June 2, 2015

Codeigniter Template

Codeigniter Template

Folder Structure
application/
     /controllers/
          /test_template.php
     /libraries/
          /Template.php
     /views/
          /template/
               /another_page_one.php
               /another_page_three.php
               /another_page_two.php
               /default_content.php
               /main_tmp.php
system/

./application/controllers/test_template.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Test_template extends CI_Controller {

     public function __construct() {
          parent::__construct();
          $this->load->library('template');
     }

     public function index() {
          $this->template->set('title', 'My Title');
          $this->template->load('template/main_tmp', 'template/default_content');
     }

     public function another_page_one() {
          $this->template->set('title', 'Another Page One');
          $this->template->load('template/main_tmp', 'template/another_page_one');
     }

     public function another_page_two() {
          $this->template->set('title', 'Another Page Two');
          $this->template->load('template/main_tmp', 'template/another_page_two');
     }

     public function another_page_three() {
          $this->template->set('title', 'Another Page Three');
          $this->template->load('template/main_tmp', 'template/another_page_three');
     }

}

/* End of file template.php */
/* Location: ./application/controllers/template.php */

./application/libraries/Template.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Template {

     var $template_data = array();
     private $data = array();

     public function __construct() {
          $this->CI =& get_instance();
     }

     public function set($name, $value) {
          $this->template_data[$name] = $value;
     }

     public function load($template = '', $view = '', $view_data = array(), $return = FALSE) {
          $this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
          return $this->CI->load->view($template, $this->template_data, $return);
     }

}

/* End of file Template.php */
/* Location: ./application/libraries/Template.php */

./application/views/template/another_page_one.php
<h3>Another Page One</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

./application/views/template/another_page_three.php
<h3>Another Page Three</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

./application/views/template/another_page_two.php
<h3>Another Page Two</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

./application/views/template/default_content.php
<h3>Default Content</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

./application/views/template/main_tmp.php
<ul>
     <li><?=anchor('test_template', 'Home');?></li>
     <li><?=anchor('test_template/another_page_one', 'Another page 1');?></li>
     <li><?=anchor('test_template/another_page_two', 'Another page 2');?></li>
     <li><?=anchor('test_template/another_page_three', 'Another page 3');?></li>
</ul>
<?=$contents;?>

Categories: ,

0 comments:

Post a Comment

luvne.com resepkuekeringku.com desainrumahnya.com yayasanbabysitterku.com

Copyright © Click | Powered by Blogger