Creating a Template Helper for CodeIgniter

first you create /helper/template_helper

<?php if (! function_exists('renderPage')) { 	
function renderPage($view, $data){ 		        
         $CI =& get_instance(); 		
         $CI->load->view('t/header', $data);
         $CI->load->view($view, $data);
         $CI->load->view('t/footer');
	}
}

then in controller you can call function like this

function index(){
  $this->load->helper('template');
  $data['name_title'] = 'Title Page In Head Tag';
  renderPage('index_view',$data);
}

source: http://varun1505.com/blog/2013/09/01/creating-a-template-helper-for-codeigniter/

Advertisements

Selected on Dropdown Select PHP

<select name=”kategori” id=””>
<option value=””> — Pilih Kategori –</option>
<?php
foreach ($categ as $c) {
if ($c->kategori == $u->kategori) {$select = ‘selected=”selected”‘;
} else { $select = ”;}
echo “<option value=\”{$c->kategori}\” {$select}>{$c->kategori}</option>”;
}
?>
</select>