Prado/YII PHPExcel Auto Load bug - With Solution

Topics: Developer Forum, User Forum
Jul 27, 2011 at 1:13 PM

Well this was a headache and then some.

The problem is Prado has a Auto Loading process that can cause 3rd party or additional libraries to break and act strange if they also have a Auto Loading process.

The Solution is to turn off Prado's Auto Loading process, Load the 3rd party/Additional library and then turn Prado's Auto Loading process back on.

Here is what it looks like: (In this example I'm using the namespace instead of the path alias)


$phpExcelPath = Prado::getPathOfNamespace('Application.Core.php_excel.Classes');

// Disable Prado Auto Loading process
spl_autoload_unregister(array('Prado','autoload'));

// Add PHP Excel
require_once($phpExcelPath.'/PHPExcel.php');
require_once($phpExcelPath.'/PHPExcel/Writer/Excel2007.php');

// Do PHP Excel stuff here

// Reload Prado Auto Loading process
spl_autoload_register(array('Prado','autoload'));




Reference: http://www.ramirezcobos.com/2010/11/05/how-to-use-phpexcel-with-yii/ 

They are using YII but the process is very similar

Jan 7, 2014 at 11:38 AM
Very grateful, not only works perfect for these frameworks, also meet with any of _autoload...