vlad
vlad

Reputation: 5

Loading PHPExcel library in Zend Framework 2 only in current action

I would like to use PHPExcel library in a zend framework 2 project. But I don't want to load it for the overall project, just in one particular action. How can I do this?

Upvotes: 0

Views: 278

Answers (2)

user132879
user132879

Reputation: 1

To use PHPOffice/PHPExcel library into zend framework 2, you can use the zf2 module MvlabsPHPExcel. Through composer:

$ php composer.phar require mvlabs/mvlabs-phpexcel

And after that you'll be able to use inside you controller particular action:

$phpExcelObject = $this->serviceLocator->get('mvlabs.phpexcel.service')->createPHPExcelObject();

I recommend to use dependency injection in your controller by injecting the 'mvlabs.phpexcel.service' as a controller dependency.

Upvotes: 0

Alain Pomirol
Alain Pomirol

Reputation: 828

If your PHPExcel library is load by composer.phar yo can access the class through:

$objPHPExcel = new \PHPExcel();

else, you must include path of your library before use :

/** Include path **/
ini_set('include_path', ini_get('include_path').';<relative directory path>/');

/** PHPExcel */
include 'PHPExcel.php';

$objPHPExcel = new PHPExcel();

Upvotes: 1

Related Questions