Codeigniter “Master page” Library

I was an Asp.Net Developer Before Starting Php , One of the Best Concepts in Asp.Net is the Master page which simplify working with our views by adding a common layout for all pages

Then I Found out that the layout divided into header , footer , sidebar which are constant in design all over the website just differs in content and the main content which differs according to the requested URL

Here’s a Link to the Master Page Library that’s help in that task with simple and less Code

1. Configuration :

  • sub_path : The path of your view files in views folder
  • master_output : The Output of Your Master page (‘view’ , ‘parser’)
  • header : Name of Your Header File
  • footer : Name of Your Header File

* Note : Each of these Parameters has default values (“front” , “view” , “header.php” , “footer.php” ) respectively

2. Functions :

  • apply($page, $data, $type = ‘view’, $lang = ”, $return = ‘0’) and it’s used to apply common layout
  • apply_ajax($page, $data, $type = ‘view’, $lang = ”, $return = ‘0’) and it’s used to apply partial view as in ajax
  • $page : view file name $data : the data for view $type : type of rendering the current page Default is “view” $lang : used for language folder (could be any sub-folder with sub_path) Default is empty $return : either to return the view in string or in browser Default is FALSE

3. Example :

$config[‘sub_path’] = ‘admin’;

$config[‘master_output’] = ‘view’;

$config[‘header’] = ‘header.php’;

$config[‘footer’] = ‘footer.php’;


$this->masterpage->apply($page , $data);

Originally published at on May 5, 2012.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.