Also available in these languages:
DeutschEnglishEspañolFrançaisBahasa Indonesia日本語polskiPortuguêsRomâniaРусскийsvenska简体中文

Using 3rd-Party Libraries

Yii is carefully designed so that third-party libraries can be easily integrated to further extend Yii's functionalities. When using third-party libraries in a project, developers often encounter issues about class naming and file inclusion. Because all Yii classes are prefixed with letter C, it is less likely class naming issue would occur; and because Yii relies on SPL autoload to perform class file inclusion, it can play nicely with other libraries if they use the same autoloading feature or PHP include path to include class files.

Below we use an example to illustrate how to use the Zend_Search_Lucene component from the Zend framework in a Yii application.

First, we extract the Zend framework release file to a directory under protected/vendors, assuming protected is the application base directory. Verify that the file protected/vendors/Zend/Search/Lucene.php exists.

Second, at the beginning of a controller class file, insert the following lines:

Yii::import('application.vendors.*');
require_once('Zend/Search/Lucene.php');

The above code includes the class file Lucene.php. Because we are using a relative path, we need to change the PHP include path so that the file can be located correctly. This is done by calling Yii::import before require_once.

Once the above set up is ready, we can use the Lucene class in a controller action, like the following:

$lucene=new Zend_Search_Lucene($pathOfIndex);
$hits=$lucene->find(strtolower($keyword));
$Id: extension.integration.txt 1622 2009-12-26 20:56:05Z qiang.xue $
If you found any typos or errors in the tutorial, please create a Yii ticket to report it. If it is a translation error, please create a Yiidoc ticket, instead. Thank you.

Total 1 comment:

#388
Full integration
by KJedi at 6:51am on June 17, 2009.

Yes, that works fine, but from time to time you need to integrate with something more, than one class. See more about this in my cookbook post

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.