Yii 1.1: Integrating with other frameworks

7 followers

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 4 comments

#3578 report it
Maurizio Domba Cerin at 2011/04/20 04:05am
@nettrity

Chek all the PHP documentation about it...

If you have read the PHP documentation... you know that by using spl_autoload_register() you can register a custom auto-loading method to be used by PHP script...

Yii registers the method YiiBase::autoload() to be used as an autoload by PHP scripts - http://www.yiiframework.com/doc/api/1.1/YiiBase#autoload-detail

And what this wiki say to do (check again the code above) is to unregister that Yii method... register the zend autoloader... and then again register the Yii one...

Hope it clears your doubts..

#3567 report it
nettrinity at 2011/04/19 01:49pm
@mdomba

That is PHP autoloader. How does it related to Yii?

#3558 report it
Maurizio Domba Cerin at 2011/04/19 04:01am
@nettrity

For autoloading concept check the PHP documentation

http://php.net/manual/en/language.oop5.autoload.php

#3553 report it
nettrinity at 2011/04/18 11:29pm
What is Yii Autoloader?

Maybe I am a beginner, but I haven't seen anything called Yii autoloader after reading the Guide. Are you talking about Yii::import()? or return array( 'class'=> application.component.xxxx, ...) ?

Leave a comment

Please to leave your comment.

Write new article
  • Written by: KJedi
  • Category: Tutorials
  • Yii Version: 1.1
  • Votes: +5 / -1
  • Viewed: 16,241 times
  • Created on: Jun 17, 2009
  • Last updated: Jun 17, 2009