CodeIgniter Forums
views and controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: views and controllers (/showthread.php?tid=41204)



views and controllers - El Forum - 05-01-2011

[eluser]Unknown[/eluser]
I have several controllers that load the same views (besides specific views for each controller).
Is there a way to do it only once ?


views and controllers - El Forum - 05-01-2011

[eluser]InsiteFX[/eluser]
Create a template_view, something like this add more if you need them.
Code:
<?php $this->load->view(header_view);?>

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

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

Controller:
Code:
$this->load->vars($data);
$this->load->view('template_view');

InsiteFX


views and controllers - El Forum - 05-01-2011

[eluser]Unknown[/eluser]
thanks but what I meant was regarding the $data...


views and controllers - El Forum - 05-01-2011

[eluser]dUspan[/eluser]
you mean this?

<?php
$data['body']="view body content";
$this->load->view('body_view',$data);
?>


views and controllers - El Forum - 05-01-2011

[eluser]InsiteFX[/eluser]
You mentioned nothing about data all about views!
Then look into creating a MY_Controller in the CodeIgniter User Guide

This can be used any place in your code and makes the data avaiable to all your views!
Code:
$this->load->vars($data);

InsiteFX