在CodeIgniter中写入文件时出错

时间:2013-10-19 21:56:14

标签: php codeigniter

我从头开始编写php codeigniter 我正在尝试知道文件助手中的write_file函数 这是我的控制器

 <?php

 class Files extends CI_Controller {

    var $file;
    function Files()
    {
        $this->file = "application" . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR . "hello.txt";
    }

    function write_file(){

        $data = "Hello World !! :)";

        write_file($this->file,$data ,'a');
        echo "writing is finishing...";
    }
 }

我的版本是2.1.4,befog我把'a'它很好但是在我添加它之后 它给了我这个错误

Call to undefined function write_file() in C:\wamp\www\test7\application\controllers\files.php

1 个答案:

答案 0 :(得分:0)

如果你想在codeigniter中使用辅助函数,你需要先加载它:

$this->load->helper('file');

只需在控制器的构造函数中或在使用write_file()之前添加此行

相关问题