0

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

3
  • 1
    Use something like $slideContent = $this->load->view('slideshow','$slideshowData',true); this will save the slideshow view page into $slideContent. Then you can easily call the variable inside the page Commented Mar 3, 2017 at 11:07
  • where should i write this? Commented Mar 3, 2017 at 11:25
  • u declare this in controller function and use it in view page Commented Mar 3, 2017 at 11:27

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.