2016-03-07 46 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"; 
    } 
相关问题