Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why we use TRUE in load a view in CodeIgniter

Tags:

codeigniter

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

like image 215
Md. Nazmul Hosan Avatar asked May 14 '13 11:05

Md. Nazmul Hosan


Video Answer


1 Answers

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

like image 51
Akash KC Avatar answered Nov 02 '22 08:11

Akash KC