I intend to save all views files generated by Codeigniter on my desktop; I need to output the views into files like home.html, single.html, page.html inside a folder. Is there an solution for this?
问问题
3779 次
2 回答
3
实际上,您可能会将视图作为数据返回,只需将其分配给变量即可。
$string = $this->load->view('myfile', $data, true);
只要得到这个响应,创建一个文件并上传到服务器(使用 fwrite 或 ftp)。
下面是一个简单的例子:
<?php
$file = '/var/www/whatever/upload_dir/file.html';
$string = $this->load->view('myfile', $data, true);
// Write the contents back to the file
file_put_contents($file, $string );
?>
希望能帮助到你!
于 2012-04-19T16:29:31.227 回答
1
TRUE
您可以通过在调用时提供第三个参数(布尔值)来加载视图并将其作为字符串返回$this->load->view()
。从那里,您可以调用file_put_contents()
将字符串写入文件。
$view_string = $this->load->view('some_view', '', TRUE);
file_put_contents('filename', $view_string);
您还可以使用CodeIgniter File Helperwrite_file()
提供的将字符串写入文件。
于 2012-04-19T16:14:52.150 回答