Is there any way that I can get content of a PHP file in to variable?
I want to do this
$msg = $this->load->view('some_view');
but when I do this, $msg
is NULL
.
Is it possible?
To load (and display) a view in CodeIgniter, we use the built in Loader library. $this ->load->view( 'hello_world' , $data , true/false); This single line of code will tell CodeIgniter to look for hello_world. php in the application/views folder, and display the contents of the file in the browser.
Since a controller writes either to view or model - you'd pass variables to view via controller. $model = new Model(); $view = new View($model); $controller = new Controller($view); // This will assign variables to view $controller->indexAction(); echo $view->render();
It is possible:
$msg = $this->load->view('some_view', '', true);
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:
$msg = $this->load->view('some_view', '', true);
Source : http://codeigniter.com/user_guide/general/views.html
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