Reputation: 5
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
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
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