mirror of
https://github.com/yiisoft/yii.git
synced 2026-03-14 03:56:53 +01:00
47 lines
1.8 KiB
Plaintext
47 lines
1.8 KiB
Plaintext
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](http://us3.php.net/manual/en/function.spl-autoload.php)
|
|
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](http://www.zendframework.com/manual/en/zend.search.lucene.html)
|
|
component from the [Zend framework](http://www.zendframework.com) in an Yii application.
|
|
|
|
First, we extract the Zend framework release file to a directory
|
|
under `protected/vendors`, assuming `protected` is the
|
|
[application base directory](/doc/guide/basics.application#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:
|
|
|
|
~~~
|
|
[php]
|
|
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:
|
|
|
|
~~~
|
|
[php]
|
|
$lucene=new Zend_Search_Lucene($pathOfIndex);
|
|
$hits=$lucene->find(strtolower($keyword));
|
|
~~~
|
|
|
|
|
|
<div class="revision">$Id$</div> |