Introduce php files and plug-ins in Yii

Source: Internet
Author: User
Introduction of PHP files and plug-ins in Yii: zccst I. set environment variables (in PHP) echoget_include_path (); & nbsp; obtain all current environment variables. That is, the code in the project has been referenced. Set_include_path (.. PATH_SEPARATOR.Yii: introduce php files and plug-ins in app () Yii
Author: zccst
1. set environment variables (in PHP)

Echo get_include_path (); // Obtain all current environment variables. That is, the code in the project has been referenced.
Set_include_path ('. '. PATH_SEPARATOR. yii: app ()-> basePath. '/lib/PHPExcel '. PATH_SEPARATOR. get_include_path (); // add an environment variable at the beginning.
Echo get_include_path ();

The two differences show that the new environment variable is successfully set using the set_include_path () function.

II. Reference in YII

1, Yii: import ("application. lib. PHPExcel .*");
Explanation:
Application is equivalent to the protected folder.


2. introduce the base path in ../config/main. php of yii.
return array('basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',  ......    // autoloading model and component classes'import'=>array('application.models.*','application.components.*','application.helpers.*', // helper methods'ext.mail.Message','application.lib.*',),)

In the code, you can reference
Yii: app ()-> basePath


3. use
// Introduce the PHPExcel file require_once 'phpexcel. php'; require_once 'phpexcel/IOFactory. php'; require_once 'phpexcel/Writer/excel2007.php'; require_once 'phpexcel/Writer/excel5.php ';


3. Reference plug-ins in Yii
Note: plug-ins and extensions are different.
1. put the source code in project/ckeditor /*
2. Reference in code create and update
 basePath = Yii::app()->baseUrl.'/ckeditor/';// Replace a textarea element with an id (or name) of "textarea_id".$CKEditor->replace("News_content");?>


Method 2:
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 .*');
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.

Third, once we have set it, we can use it in the controller. For example
$ Lucene = new Zend Search Lucene ($ pathOfIndex );
$ Hits = $ lucene-> find (strtolower ($ keyword ));



4. introduce any other files to a page
For example, to directly use ../components/RMSClient. php in ../controllers/OutsourceController. php, you can use the following method:
Require_once (dirname (_ FILE __). "/.. /components/RMSClient. php "); // note the following method for importing. the require_once (Yii: app ()-> baseUrl is not found. "/protected/components/RMSClient. php "); // cause: include and require contain the file path strength on the server, which has no direct relationship with the url. // If you want to use the yii: app () method, you can use the Yii: app ()-> basePath.


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.