phpspreadsheet语法错误,意外' require_once' (T_REQUIRE_ONCE),期待功能(T_FUNCTION)

时间:2018-02-19 03:13:36

标签: class controller opencart phpspreadsheet

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

  

解析错误:语法错误,意外' 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');

1 个答案:

答案 0 :(得分:2)

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

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

class ControllerToolImportExport extends Controller {
    function index() {
        // Put your code here.
    }
}