Integrating with other frameworks

When you need to integrate with other frameworks (e.g. Zend Framework), you have to follow these steps:

  1. Create protected/vendors/ (e.g. protected/vendors/Zend)
  2. In your action/controller put Yii::import('application.vendors.<frameworkName>.*')
  3. If you need more, than just 1-2 classes (e.g. full package in the framework), you should register it's autoload method. Most frameworks implement their own autoload, that is different from Yii's one.

I saw this hint in this forum thread and adopted it to Zend:

require_once 'Zend/Loader/Autoloader.php';
spl_autoload_unregister(array('YiiBase','autoload'));
spl_autoload_register(array('Zend_Loader_Autoloader','autoload'));
spl_autoload_register(array('YiiBase','autoload'));

Idea is the following. You unregister Yii's autoload function, then register framework's one and then Yii's one again. This leads to the effect, when php is trying to use 3rd party autoload first and loads correct classes. If none found (because you actually called Yii class), it tried Yii's autoload. So everything is OK :)

Total 3 comments:

#630
Captcha
by tixrus at 9:49pm on September 2, 2009.

How can I substitute one of ZFs Captchas for the Yii one in the demo application?

#631
more explanation please
by tixrus at 9:32pm on September 2, 2009.

you unregister the original one, then register the foreign one, then re register the original one.

So I presume it wouldn't do to just register the foreign one

So this concludes that the first one registered will be the first one used, and you want to give preference to the foreign one. But there shouldn't be any conflict of names anyway.

Do you have a boundary case or something so I can understand this better?

#1161
new function, registerAutoloader()
by jaxyeh at 2:50pm on February 23, 2010.

Someone mentioned on the internet that as of version 1.0.10 there is a convenience method to do this, see http://www.yiiframework.com/doc/api/1.0.10/YiiBase#registerAutoloader-detail.

Anyone has example code of this function?

Your Comment:

You may enter comment using Markdown syntax.

Please login with your forum account.
Note: you must have at least ONE forum post with your account.