How to load view as data in CodeIgniter


In this tutorial I will let you know how to load view as data in CodeIgniter. If you want to load a view without sending output data to browser in CodeIgniter this tutorial will help you.

Load view output to Browser

$this->load->view('header');

Load View as data

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:

$data_view = $this->load->view('data_view', '', true);