CodeIgniter Forums
One header in all controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: One header in all controllers (/showthread.php?tid=58234)



One header in all controllers - El Forum - 05-25-2013

[eluser]raduenea[/eluser]
I have a header views like:
Code:
<div id="big_table">

<div id="banner">
    banner
    </div>
    
<div id="left">
    &lt;?php



foreach ($array as $key => $value):

  
    //echo $key . ' -> ' . $value . '<br>';
    echo anchor('picturi/' . $value['link'] . '/' . $value['id'] , $key , array('title' => 'Picturi ' . $value['link'])) . '<br>';
endforeach;


//echo $link;
  ?&gt;
    </div>

and footer views:
Code:
</div>

<div class="clear"></div>

&lt;/body&gt;
&lt;/html&gt;

And two classes.
Home controller
Code:
class Home extends CI_Controller {
public function index()
{
  $data['title'] = "About the Code Igniter Sample Application";
  $data['array'] = array(
          'Abstracte' => array (
              'link' => 'abstracte',
              'id' => '1'
              ),
        'Munti' => array (
              'link' => 'munti',
              'id' => '2'
              ),
        'Oameni' => array (
               'link' => 'oameni',
               'id' => '3'
               )
        );

  //$data['link'] =  $this->uri->segment(2, 0);

  $this->load->helper('url');
  $this->load->helper('array');

  $this->load->view('header', $data);
  $this->load->view('home_message');
  $this->load->view('footer');
}



}

and
Picturi controller
Code:
class Picturi extends CI_Controller {


public function general()
{
  
  $data['title'] = "Picturi";
  
  $data['id'] = $this->uri->segment(3);
  
  if($data['id'] == 1)
  {
   $data['show_pic'] = array('unu','doi','trei');
  }
  elseif($data['id'] == 2)
  {
   $data['show_pic'] = array('patru','cinci','sase');
  }
  
  
  $this->load->helper('url');

  $this->load->view('header', $data);
  $this->load->view('picturi');
  $this->load->view('footer');
}


}

In header I have the menu that I need in all controllers. That menu is generated with array in home controller.
I can copy and paste the array code in picturi controller, but I will have more controllers and I dont't think that copy/paste it's ok.

Please help me where can I generate the header only one to be include in all controllers ?

Thanks


One header in all controllers - El Forum - 05-25-2013

[eluser]jairoh_[/eluser]
you should have another view that loads the header, footer and the content you want to view.

ex.

controller
Code:
$data [ 'content' ] = 'name of the view you wan to display in between' ;
$this->load->view( 'my_view', $data );

my_view
Code:
$this->load->view('header', $data);
$this->load->view( $content );
$this->load->view('footer');