• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Sovled] PHPSpreedsheet with Codeigniter

#1
I am new to using composer with codeigniter I have success fully installed composer and PHP Spreedsheet How ever when I go to my test function 

I get error below. Not sure on what to do for this it may be simple for other experienced composer users.

https://phpspreadsheet.readthedocs.io/en/develop/

Code:
An uncaught Exception was encountered

Type: ParseError

Message: syntax error, unexpected 'use' (T_USE)

Filename: C:\xampp\htdocs\riwakabowlingclub\application\modules\admin\controllers\event\Events.php

Line Number: 96

Backtrace:

File: C:\xampp\htdocs\riwakabowlingclub\index.php
Line: 315
Function: require_once


PHP Code:
public function test() {
 
  require(APPPATH 'vendor/autoload.php');

 
  use PhpOffice\PhpSpreadsheet\Spreadsheet;
 
  use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 
 
  $spreadsheet = new Spreadsheet();
 
  $sheet $spreadsheet->getActiveSheet();
 
  $sheet->setCellValue('A1''Hello World !');

 
  $writer = new Xlsx($spreadsheet);
 
  $writer->save('hello world.xlsx');




Thank you for your help
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
(10-03-2017, 04:23 PM)wolfgang1983 Wrote: I am new to using composer with codeigniter I have success fully installed composer and PHP Spreedsheet How ever when I go to my test function 

I get error below. Not sure on what to do for this it may be simple for other experienced composer users.

https://phpspreadsheet.readthedocs.io/en/develop/

Code:
An uncaught Exception was encountered

Type: ParseError

Message: syntax error, unexpected 'use' (T_USE)

Filename: C:\xampp\htdocs\riwakabowlingclub\application\modules\admin\controllers\event\Events.php

Line Number: 96

Backtrace:

File: C:\xampp\htdocs\riwakabowlingclub\index.php
Line: 315
Function: require_once


PHP Code:
public function test() {
 
  require(APPPATH 'vendor/autoload.php');

 
  use PhpOffice\PhpSpreadsheet\Spreadsheet;
 
  use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 
 
  $spreadsheet = new Spreadsheet();
 
  $sheet $spreadsheet->getActiveSheet();
 
  $sheet->setCellValue('A1''Hello World !');

 
  $writer = new Xlsx($spreadsheet);
 
  $writer->save('hello world.xlsx');




Thank you for your help

I think now I may have solution by placing the use above the class like so seems to work now


PHP Code:
<?php

require(APPPATH 'vendor/autoload.php');

use 
PhpOffice\PhpSpreadsheet\Spreadsheet;
use 
PhpOffice\PhpSpreadsheet\Writer\Xlsx;


class 
Events extends MX_Controller {



There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#3
In application/config/config.php you can set the composer path

PHP Code:
/*
|--------------------------------------------------------------------------
| Composer auto-loading
|--------------------------------------------------------------------------
|
| Enabling this setting will tell CodeIgniter to look for a Composer
| package auto-loader script in application/vendor/autoload.php.
|
|    $config['composer_autoload'] = TRUE;
|
| Or if you have your vendor/ directory located somewhere else, you
| can opt to set a specific path as well:
|
|    $config['composer_autoload'] = '/path/to/vendor/autoload.php';
|
| For more information about Composer, please visit http://getcomposer.org/
|
| Note: This will NOT disable or override the CodeIgniter-specific
|    autoloading (application/config/autoload.php)
*/
$config['composer_autoload'] = FALSE

https://github.com/bcit-ci/CodeIgniter/b...g.php#L139
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.