Share Pastebin
Guest
Public paste!

yingyes

By: a guest | Apr 4th, 2008 | Syntax: None | Size: 2.57 KB | Hits: 156 | Expires: Never
Copy text to clipboard
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Default_controller extends Controller
  4. {
  5.     function Default_controller()
  6.     {
  7.         parent::Controller();
  8.     }
  9.         var $module;
  10.         var $method;
  11.         var $data=array();
  12.  
  13.         function _remap()
  14.     {
  15. //              modules::load('search');
  16.  
  17.         $this->module = $this->uri->segment(1) OR $this->module = 'home';
  18.         $this->method = $this->uri->segment(2) OR $this->method = 'index';
  19.  
  20.                 $this->init();
  21.  
  22.                 if(modules::exists($this->module,$this->module,'controllers/')!=NULL)
  23.                 {
  24.                         if(modules::exists($this->method,$this->module,'methods/')!=NULL)
  25.                         {
  26.                                 $content = modules::run($this->module, $this->data, $this->method);  
  27.                         }
  28.                         else
  29.                         {
  30.                                 $content = modules::run($this->module, $this->data, 'index');  
  31.                         }
  32.                 }
  33.                 else
  34.                 {
  35.                         redirect('');
  36.                 }
  37.                 $this->render($content);
  38.     }
  39.         function init()
  40.         {
  41.                 $this->data=$this->lang->language;
  42.                 $this->data['username'] = $this->session->userdata('username');
  43.                 $this->data['user_group'] = $this->session->userdata('user_group');
  44.                 $this->data['logged_in']= $this->session->userdata('logged_in');
  45.                 $this->data['logged_in_value']=$this->config->item('logged_in_value');
  46.         $this->data['response']=$this->session->flashdata('response');
  47.                 $this->data['error']=$this->session->flashdata('error');
  48.                 $this->data['message']=$this->session->flashdata('message');
  49.                 $this->data['current_page']=$this->module;
  50.                 $this->data['current_action']=$this->method.'_tpl';
  51.                 $this->data['query_count']=$this->template_model->query_count;
  52.                 $this->data['page_title']=$this->method." - ".$this->module." - ".site_url();
  53.                 $this->data['uri_string']=$this->uri->uri_string();
  54.                 $this->data['segment_array']=$this->uri->segment_array();
  55.                 $this->data['total_segments']=$this->uri->total_segments();
  56.                 $this->data=array_merge($this->data,$this->environ->data['template_layout']);
  57.                 $this->data=array_merge($this->data,$this->environ->data);
  58.         }
  59.  
  60.     function render($content,$template="ci:default_layout")
  61.     {      
  62.  
  63.                 //This calls the active template index page
  64.         $layout = array(
  65.                         'template'=> $content//$this->smarty_parser->parse('ci:'.$this->template.'/index',$content,true)
  66.         );
  67.                 /*contains only <?=$template?>*/
  68.                 $this->smarty_parser->parse($template,$layout);
  69.     }
  70.     function error($method, $data = '')        
  71.     {
  72.         //trap unknown method calls, suppress error message
  73.         if ($content = parent::error($method, $data, FALSE))
  74.         {
  75.             return $content;
  76.         }
  77.        
  78.         redirect('');
  79.     }
  80. }
  81. ?>