-2

I am getting this error when I put it in the class controller. It works fine if I remove the class controller. How do I fix it?

Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE), expecting function (T_FUNCTION) in D:\xampp\htdocs\m2302\admin\controller\tool\import_export.php on line 9 expecting function

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');
Graham
  • 7,431
  • 18
  • 59
  • 84

1 Answers1

2

You code is all just "loose" in the class.

It should be in a method (function) instead e.g.:

class ControllerToolImportExport extends Controller {
    function index() {
        // Put your code here.
    }
}
Paul Feakins
  • 719
  • 5
  • 7
  • 1
    Stackoverflow is a place where you ask a specific technical question and get a specific answer which you have, it's not a place where we code every step of a project for you because you don't know how to code. – Paul Feakins Feb 20 '18 at 09:50