title: How to include header file dynamically through constructor for dynamic content in codeigniter
body: <blockquote>
    <p>Hi, I am stuck on a problem where i have to echo dynamic meta
    description and meta keywords for a specific page. I have included the
    header file into the constructor and it contains a code that has
    language change option through session. </p>
    
    <p>I have a table named contents which contains content of the pages and
    also 2 columns (metakeywords,metadescription). I want them to
    dynamically display on each page where i get the id of the page.</p>
    
    <p>Below is the code so far : please help</p>
  </blockquote>
  
  <p><strong>This is controller :</strong></p>
  
  <pre><code>public function __construct(){
  $this-&gt;load-&gt;model('home_m');
  $data['query'] = $this-&gt;home_m-&gt;seo($id);
  $this-&gt;load-&gt;view('site/include/head', $data);
  $header = $this-&gt;header();
  $this-&gt;load-&gt;view('site/include/header', $header);
  }
  
  public function header(){        
          $site_setting = $this-&gt;home_m-&gt;getRow('general',array('gen_id' =&gt; 1));
          $data['site_setting'] = $site_setting;
          $header_links="select * from ".PRE_FIX."header_links";
          $data['header_links'] = $this-&gt;home_m-&gt;getCustomRecords($header_links);
  $this-&gt;set_language();
  if ( $site_setting-&gt;language == 1){
              $language = "english";
          } else {
              $language = "french";
          }
  
          if ( $this-&gt;session-&gt;userdata("setLanguage") != ""   ) {
              $language = $this-&gt;session-&gt;userdata("setLanguage");
          }
          $data['language'] = $language;
           return $data;
      }
  </code></pre>
  
  <p>Now for eg: i want to display the header metakeywords and meta description on the following page which is webhosting.</p>
  
  <pre><code>public function webhosting(){
  $this-&gt;set_language();
  $language =  $this-&gt;session-&gt;userdata("setLanguage");
  $get_plans = "Select * from gdn_planstesting where page='webhosting'";
  $data['get_plans'] = $this-&gt;home_m-&gt;getCustomRecords($get_plans);
  $this-&gt;load-&gt;view('site/webhosting', $data);
  $this-&gt;load-&gt;view('site/include/footer',$data);
  }
  </code></pre>
  
  <p><strong>This is model :</strong></p>
  
  <pre><code>public function getCustomRecords($customQuery)
      {
          $recordSet = $this-&gt;db-&gt;query($customQuery);
          return $recordSet-&gt;result();
      }
  
  function seo($id){
  $query = $this-&gt;db-&gt;query("SELECT * FROM gdn_planstesting WHERE planstestingid='$id'");
  return $query-&gt;result_array();
      }
  </code></pre>
  
  <p><strong>This is view :</strong> </p>
  
  <pre><code>foreach($get_plans as $pl) {
      $pid = $pl-&gt;planstestingid;
      $pname = $pl-&gt;planname;
      $planStatus=$pl-&gt;plan_status;
  }
  
  foreach($query as $value){
  echo $query-&gt;id;
  }
  **This is the header file :**
  
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt;
      &lt;meta name="description" content="" /&gt;
      &lt;meta name="keywords" content=""&gt;
      &lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;assets/front/css/style.css" type="text/css"&gt;
      &lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;assets/front/css/bootstrap.css" type="text/css"&gt;
      &lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;assets/front/css/font-awesome.css" type="text/css"&gt;
      &lt;link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,300,700' rel='stylesheet' type='text/css'&gt;
      &lt;link href='https://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'&gt;
      &lt;title&gt;Your title&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;header&gt;
              &lt;div class="container-fluid headertop"&gt;
              &lt;!-- &lt;div class="container-fluid"&gt; --&gt;
                  &lt;div class="container"&gt;
                      &lt;div class="row"&gt;
      &lt;?php
          if($language == "english"){
  
              $lang1 = "class='active'";
              $lang2 = "";
          } else {
  
              $lang1 = "";
              $lang2 = "class='active'";
          }?&gt;
              &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/header&gt;
  </code></pre>