Yii Framework Forum: Yii Autoload Doesnt Works After Register Another Autoload - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Autoload Doesnt Works After Register Another Autoload Rate Topic: -----

#1 User is offline   prchakal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 20-January 10

Posted 09 May 2013 - 07:58 PM

Hi,

I have to register a new autoloader from a library called PagSeguro, but the problem is when i register it, the Yii autloader doesnt find Yii Classes more :(

My code:
// inclui biblioteca do PagSeguro
Yii::import('ext.*');
spl_autoload_unregister(array('YiiBase', 'autoload'));
require_once(Yii::app()->basePath .'/extensions/PagSeguroLibrary/PagSeguroLibrary.php');
spl_autoload_register(array('YiiBase', 'autoload'));


My error:

Quote

Fatal error: Class 'CExceptionEvent' not found in ..../protected/framework/base/CApplication.php on line 714 Fatal error: Class 'CListIterator' not found in ..../protected/framework/collections/CList.php on line 90


Can anyone help me?
0

#2 User is offline   jneto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 19-November 12
  • Location:Portugal

Posted 09 May 2013 - 09:00 PM

Did the PagSeguro lib use autoload ?

If it does, you can not use YII API after spl_autoload_unregister. To do that you have to spl_autoload_register . So it's normal that Yii::app() doen't work.

You can


Yii::import('ext.*');

$path= Yii::app()->basePath; // the lib path

spl_autoload_unregister(array('YiiBase', 'autoload'));
require_once($path .'/extensions/PagSeguroLibrary/PagSeguroLibrary.php');

........ do the stuff i need and then register YII autoload

spl_autoload_register(array('YiiBase', 'autoload'));




if PagSeguro don't use autoload, you don't need to register and unregister the autoload.

Hope it helps.
0

#3 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 10 May 2013 - 04:50 AM

Some autoloaders allow you to chain another autoloader ... they return false on failure so that the next autoloader in the chain can give it a try. That of PHPExcel is this kind, for example.

Other autoloaders don't allow it ... they throw exception on failure and take away the chances from the next one in the chain. Unfortunately, that of Yii is this kind.

So, you'd better check which kind of autoloader PagSeguro has.

[EDIT]
For reference:
http://www.yiiframew...-with-yii#c8432
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users