How does YII call a third-party PHP class?

Source: Internet
Author: User
YII how to call a third-party PHP class first, you must understand RootAlias for convenience. Yii predefines the following root aliases: & nbsp; system: indicates the Yii Framework directory; & nbsp; zii: indicates the Zii Library Directory; & nbsp; application: indicates the basic directory of the application; & how does nbs YII call a third-party PHP class?
First, you must understand Root Alias
For convenience, Yii predefines the following root aliases:
System: indicates the Yii Framework directory;
Zii: indicates the Zii Library Directory;
Application: indicates the basic directory of the application;
Webroot: indicates the directory where the script file is located. This alias is valid from version 1.0.3.
Ext: Contains all third-party extensions. This alias is valid from Version 1.0.8.

* Import Class
You can use aliases to easily import class definitions. For example, if we want to include the definition of the CController class, we can call the following code:
Yii::import('system.web.CController');

The import method is more efficient than include and require. The imported class definition is not actually included until it is referenced for the first time. Multiple imports of the same namespace will be much faster than include_once and require_once.

Tip: when referencing a class defined by the Yii Framework, we do not need to import or include it. All core Yii classes have been imported in advance.


* Reference the third Database
First, for example, we want to use Zend framework. Decompress the zend framework to prtected/vendors. the current folder is protected/vendors/Zend/Search/Lucene. php.

Second, insert the following code in the header of the controller file.
Yii: import ('application. vendors. * '); // it can be configured in config/main. php.
Require once ('zend/Search/Lucene. php ');
The above code contains the Lucene. php class file. Because we use relative paths, we need to change the PHP file loading path. Yii: import must be before require_once.

Prinsipe

Good

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.