Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 1.35 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Codeigniter Core/MY_Controller help it to work
  2. class MY_Controller extends CI_Controller {
  3.  
  4.   protected $data = array();
  5.  
  6.   function __construct() {
  7.     parent::__construct();
  8.   }
  9.  
  10.   function render_page($view) {
  11.     //do this to don't repeat in all controllers...
  12.     $this->load->view('templates/header', $this->data);
  13.     //menu_data must contain the structure of the menu...
  14.     //you can populate it from database or helper
  15.  
  16.     $this->load->view($view, $this->data);
  17.     $this->load->view('templates/footer', $this->data);
  18.   }
  19.  
  20. }
  21.        
  22. class Home extends MY_Controller {
  23.          function __construct() {
  24.     parent::__construct();
  25.   }
  26.  
  27.         public function view($page = 'home')
  28.         {
  29.          $this->load->helper('text');
  30.             $data['records']= $this->services_model->getAll();
  31.             if ( ! file_exists('application/views/pages/'.$page.'.php'))
  32.             {
  33.                 // Whoops, we don't have a page for that!
  34.                 show_404();
  35.             }
  36.  
  37.             $data['title'] = ucfirst($page); // Capitalize the first letter
  38.  
  39.  
  40.             $this->load->view('pages/'.$page, $data);
  41.  
  42.  
  43.         }
  44.        
  45. +pages
  46.   +home.php
  47. +templates
  48.   +footer.php
  49.   +header.php.
  50.        
  51. $config['base_url'] = 'http://localhost/~ytsejam/kirmiziblog/';
  52. $config['index_page'] = 'index.php';
  53. $route['default_controller'] = 'pages/view';
  54. $route['(:any)'] = 'pages/view/$1';