3

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
shihabudheen
  • 696
  • 8
  • 26
  • Have you checked the obvious things such as directory permissions, path name correct etc? Have you tried writing directly with [fwrite](http://php.net/fwrite) to get direct output? Need more information. – LuckySpoon Feb 19 '13 at 11:34
  • file writing is working when I assign string to variable `$ViewData`,ie, `$ViewData='test writing content'`. When I am trying to load a view file, It will not working. – shihabudheen Feb 19 '13 at 11:36

1 Answers1

4

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

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162