使用 php 写入 php 文件后出现意外公共错误



我的方法在类内,但我仍然收到错误

错误

:语法错误,意外的"公共"(T_PUBLIC(,预期结束 文件中的 E:\xampp\htdocs\crud\application\controllers\student.php on 第 1 行。

可能是因为我正在从 php 编写 php 文件

PHP文件编写代码:

$file_data_write = "n".'public function '.$table_name.'(){' . "n" . '$this->load->view("'.$view_location.'");' . "n" . '}'. "n" . '}';
$file_location = APPPATH."controllers/". $view_and_controller_location;
$file_name = "/" . $view_and_controller_location . ".php";
$myfile = fopen($file_location . $file_name, "r+") or die("Unable to open file!");
fseek($myfile, -2, SEEK_END);
fwrite($myfile, $file_data_write);
fclose($myfile);

我正在写信给的类

class Student extends CI_Controller {
public function six(){
$this->load->view("student/six");
} 
}

你可能做的是在类关闭}或php关闭语法之后添加你的函数

class Test 
{
}
?>
public function ... {
}

类外不可能有"公共"功能,什么错误到底告诉你

或者您正在重写文件,而不是在末尾添加,因此公共函数将在 1 行中

最新更新