Mostly for my webapp, I try to organize it a little better. Since at the moment, every time I want to load a page, I have to do it from my controller as follows:
$this->load->view('subviews/template/headerview'); $this->load->view('subviews/template/menuview'); $this->load->view('The-View-I-Want-To-Load'); $this->load->view('subviews/template/sidebar'); $this->load->view('subviews/template/footerview');
As you can say, this is not very effective.
So, I thought that I was creating one βmainβ view - it is called template.php. This is the contents of the template:
<?php $view = $data['view']; $this->load->view('subviews/template/headerview'); $this->load->view('subviews/template/menuview'); $this->load->view($view); $this->load->view('subviews/template/sidebar'); $this->load->view('subviews/template/footerview'); ?>
And then I thought that I could call it from the controller as follows:
$data['view'] = 'homecontent'; $this->load->view('template',$data);
Unfortunately, I just can't do this job. Does anyone have any ways to do this or fixes that I can create? I tried putting "and" around $ view in template.php, but that doesn't make any difference. Common error: "Undefined variable: data" or "Can not load view: $ view.php", etc.
Thanks guys!
Jack
source share