0

I have this template view at view/include

<?php $this->load->view('include/header'); ?>
<?php $this->load->view($sidebar_column); ?>
<?php $this->load->view($result_column); ?>
<?php $this->load->view($footer_row); ?>
<?php $this->load->view('include/footer'); ?>

and i have the footer_row html at view/include

<div> this is footer row <?php echo $username ?></div>

then i call the footer_row in my controller

$data['footer_row'] = 'include/footer_row';
$this->load->view('include/template',$data);

My question, the footer_row is logged in user info and it appear in EVERY pages. With the above method I use, I have to call and retrieve the user info in every controller. How can i make it reusable so i don't need to repeat myself.

vzhen
  • 11,137
  • 13
  • 56
  • 87

2 Answers2

2

Reusability comes from making use of your constructors, and parent classes. Have a look at my previous answers:

  1. Header and Footer in CodeIgniter
  2. Constructor session validation for different functions
Community
  • 1
  • 1
Jordan Arsenault
  • 7,100
  • 8
  • 53
  • 96
0

Instead of using this method why dont you use a template library which is easy to use. I would recommend Philsturgeons Template Library but there are some more you can use any that fits to your requirements.

Williams Concepts

http://williamsconcepts.com/ci/codeigniter/libraries/template/

Phil Sturgeons's

http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/

Most Simple

http://maestric.com/doc/php/codeigniter_template

And Finally Binpresses's

http://www.binpress.com/app/codeigniter-template-library/223

Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103