Reputation: 111
I create a view file called "Mainbar" and i want to display some other view files in that, like: slideshow products and ... .
if i add $this->load->view('slideshow');
in Mainbar page the variabales I used in slideshow function wont work. what is the best way to display view files into other view and pass the variables of them too
Upvotes: 0
Views: 1807
Reputation: 409
I would declare an array that would hold the variables I want to display on the page.
So your code would look something like
$data['page_title'] = 'Why so serious';
$data['page_to_load'] = 'slideshow';
$this->load->view('Mainbar', $data);
Then in the Mainbar.php file you would load $page_to_load and the rest of that variables in your data array.
<?php $this->load->view($page_to_load); ?>
Upvotes: 0
Reputation: 6994
You can return
view contents as data
in the form of string.Using
$data= $this->load->view('slideshow', '', TRUE);
Then in another view just echo $data;
will display view slideshow
.
There is a third optional parameter lets you change the behavior of the method so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to TRUE (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:
For more visit Codeigniter Views
Upvotes: 2