1

Its maybe a redundant question.

I try to work with codeigniter. I want my own template with an header used on each page. the header is fill with widgets like a login.

I'm walking on internet to found the better way to do that. Without calling my header on each controller constructor.

forX
  • 2,063
  • 2
  • 26
  • 47
  • Please see [a previous answer of mine](http://stackoverflow.com/questions/9540576/header-and-footer-in-codeigniter/9540985#9540985). – Jordan Arsenault Feb 11 '13 at 00:04

3 Answers3

0

Watch this nettuts video: "Creating Your First Template With CodeIgniter". This video shows you exactly how to do what you are asking.

Update: You can add whatever data you need from the controller. set something like:

$data['header_info'] = 'your data';
$data['load_view'] = 'the_view';

just pass $data to the template and pass $header_info to the header. Here's what the new template would look like:

$this->load->view('my_header.php', $header_info);
$this->load->view($load_view); 
$this->load->view('my_footer.php'); 
jco
  • 667
  • 10
  • 23
  • I'm just thinking, if the header/footer view need data from controller/model. what should I do? Use the template file as a controller for getting model? – forX Feb 10 '13 at 16:41
0

simply first create folder structure under view folder like this enter image description here

in layout.php file set header, footer files.

<?php $this->load->view('includes/header');
    //print_r($this->load->view());?>

<?php $this->load->view($main_content); ?>

<?php $this->load->view('includes/footer'); ?>

Now in include folder set header and footer files enter image description here

Now in any controller you have to passe only the new content to array like this

$data['main_content']='home/welcome'; // welcome is in your new view view/home/welcome.php
$this->load->view('layout',$data);//in the controller you load which layout you want 

Now you don't need call header and footer from the controller. You have set them in layout.php and you passe only the new content to it. Same way you can do for administrator panel, in that case create layout for administrator interface.Then, you can set header and footer for administrator interface separetly.

newday
  • 3,842
  • 10
  • 54
  • 79
0

I user CodeIgniter Template.

Here u have: http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html

You can download, read a documentation and it works perfect.

You can fit your template without problems and easy in your way that you want, so I suggest to use it.

Erman Belegu
  • 4,074
  • 25
  • 39