-2

当我把它放在类控制器中时,我收到了这个错误。如果我删除类控制器,它工作正常。我如何解决它?

解析错误:语法错误,意外的 'require_once' (T_REQUIRE_ONCE),期望函数 (T_FUNCTION) 在 D:\xampp\htdocs\m2302\admin\controller\tool\import_export.php 第 9 行期望函数

class ControllerToolImportExport extends Controller {

//$dir = (strcmp(VERSION,'3.0.0.0')>=0) ? 'library/export_import' : 'spreadsheet';
//chdir( DIR_SYSTEM.$dir );
//require_once('src/PhpSpreadsheet/Spreadsheet.php');

*require_once('D:/xampp/htdocs/m2302/system/spreadsheet/autoload.php');*

//include the classes needed to create and write .xlsx file
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

//object of the Spreadsheet class to create the excel data
$spreadsheet = new Spreadsheet();

//add some data in excel cells
$spreadsheet->setActiveSheetIndex(0)
 ->setCellValue('A1', 'Domain')
 ->setCellValue('B1', 'Category')
 ->setCellValue('C1', 'Nr. Pages');
4

1 回答 1

2

你的代码在课堂上都是“松散的”。

它应该在一个方法(函数)中,而不是例如:

class ControllerToolImportExport extends Controller {
    function index() {
        // Put your code here.
    }
}
于 2018-02-19T10:42:23.987 回答