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