Controller:
$data = array();
$page['left_content'] = $this->load->view('left_content', $data, TRUE);
$page['main_content'] = $this->load->view('left_content', $data, TRUE);
$page['right_content'] = $this->load->view('left_content', $data, TRUE);
$this->load->view('home',$data);
View:
<body>
<?php if(isset($left_content)){echo $left_content;}?>
<?php if(isset($main_content)){echo $main_content;}?>
<?php if(isset($right_content)){echo $right_content;}?>
</body>
Please take look to above code. This code is used to view a page in main homepage. Now just take a test. If we just remove TRUE from code the code does not work properly. That means when we remove it then the view does not prints itself at its right place. it prints itself at the top of the main view or main home page. I have googled a lot but can not find any cause to use it. I just want to know why we just use TRUE in this code? thnx
When we pass TRUE as optional parameter while loading view, it returns the content rather than sending(displaying) data to browser directly.
You can check in documentation:
There is a third optional parameter lets you change the behavior of the function 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:
$string = $this->load->view('myfile', '', true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With