How write a new file in codeigniter?

shihabudheen picture shihabudheen · Feb 19, 2013 · Viewed 9.4k times · Source

First I want to load a view file into a variable, then I need to create a new file by writing the data to new file.ie,Like creating a copy of a view file.

$vPath = "home/muhammed/desktop/newfolder";
$ViewData=$this->load->view('test/show',TRUE);
mkdir($vPath);
write_file("$vPath/test.php", $ViewData);

But the code given is not working.

Answer

Sudhir Bastakoti picture Sudhir Bastakoti · Feb 19, 2013

change:

$ViewData=$this->load->view('test/show',TRUE);

to

$ViewData=$this->load->view('test/show', "", TRUE);

as second parameter of load->view is data and last param TRUE makes it string to be loaded to the variable See: codeIgniter Views