2016-03-07 84 views
-2
class File extends CI_Controller 
{ 
    function __construct() 
    { 
     parent::__construct(); 
     $this->load->helper('file'); 
    } 

    function writetest() 
    { 
     $data = "Hello World!"; 
     $file= "application.DIRECTORY_SEPERATOR.test_data.DIRECTORY_SEPERATOR.helloworld.txt"; 
     $write_file($file,$data); 
     echo "finished writing"; 
    } 

此代碼顯示在笨以下錯誤消息:功能名稱必須是字符串中/var/www/html/fazrin/application/controllers/file.php上線18

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: Write_file

Filename: controllers/file.php

Line Number: 18

Fatal error: Function name must be a string in /var/www/html/fazrin/application/controllers/file.php on line 18

這是18行:

$write_file($file,$data); 

回答

0

在WRITE_FILE($文件,$數據)

2

$write_file前不能使用$不變量是Codeigniter的函數。您正在將write_file()視爲varibable。所以,您必須刪除'$write_file($file,$data)中的$,如下所示:

function __construct() 
    { 
     parent::__construct(); 
     $this->load->helper('file'); 
    } 

    function writetest() 
    { 
     $data = "Hello World!"; 
     $file= "application.DIRECTORY_SEPERATOR.test_data.DIRECTORY_SEPERATOR.helloworld.txt"; 
     write_file($file,$data); 
     echo "finished writing"; 
    } 
相關問題