我正在尝试在CodeIgniter的视图文件中编写一些JSON数据。
但它显示错误:
Message: fopen() [function.fopen]: Filename cannot be empty
控制器功能如下:
public function write_in_a_view_file() {
$data = array();
$data['title'] = "Write This Title In a View File";
$view_file = $this->load->view('result.php');
$fp = fopen($view_file, 'w');
fwrite($fp, json_encode($data));
fclose($fp);
}
答案 0 :(得分:2)
您可以使用CodeIgniter文件助手。
public function write_in_a_view_file() {
$data = array();
$data['title'] = "Write This Title In a View File";
$this->load->helper('file');
$new_file_path = base_url() . '/path/to/file.php'; // modify this line to point to the actual location of the file
write_file($new_file_path, json_encode($data));
}
答案 1 :(得分:1)
fopen函数有两个参数,第一个必须是文件名,而你没有传递给第一个参数。