I'm having trouble returning a view as data in CodeIgniter 2.0.2. Im not sure if this feature is available in this version of CI and that might be the problem but I'm hoping it's not since upgrading isn't an option at the moment. We run two two web sites and on one of them we are using CI 2.1.0 which doesn't have any problems running the code below.
$view = $this->load->view('statistics/statistics_view.php', $data, true);
var_dump($view); //returns null.
I know that the file path is valid since if i just try to load the view it acts as it should. Any ideas on what might be causing this?
Sorry if its a little vague but I honestly don't have much to go on, I feel.
Thank you!
Usually, $this->load->view()
doesn't return any value. it's for loading a view and passing your data to view. Loader, as the name suggests, is used to load elements. The third parameter defaults to false
which sends the output to the screen (output buffer).
Returning views as data
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('statistics/statistics_view', '', true);
$string
should now contain the view data. Remember that if you want to use that later for display, you should echo
the variable.
For more :- https://ellislab.com/codeigniter/user-guide/general/views.html