The PHP files and plugins are introduced in Yii

Source: Internet
Author: User
Tags zend framework
Introduction of PHP files and plugins in Yii
Author: zccst
first, set the environment variables (in PHP)

Echo Get_include_path (); Gets all current environment variables. That is, the code in the project is already referenced.
Set_include_path ('. '). Path_separator. Yii::app ()->basepath. ' /lib/phpexcel '. Path_separator. Get_include_path ()); Add a new environment variable, written in front.
Echo Get_include_path ();

With two differences, you can see that using the Set_include_path () function, setting a new environment variable succeeds.

ii. references in Yii

1,yii::import ("application.lib.phpexcel.*");
Explain:
Application is equivalent to the protected folder.


2, in Yii's. /config/main.php, the introduction of the base path
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 code, you can use the following methods to reference
Yii::app ()->basepath


3, used in controller
Introduction of Phpexcel Related Documents require_once ' phpexcel.php '; require_once ' phpexcel/iofactory.php '; require_once ' PHPExcel/Writer/ excel2007.php '; require_once ' phpexcel/writer/excel5.php ';


iii. referencing plugins in Yii
Note: Plugins and extensions are not the same
1, source stacking in project/ckeditor/*
2, referencing in code create,update
 
  BasePath = Yii::app ()->baseurl. ' /ckeditor/';//Replace a TEXTAREA element with an ID (or name) of "textarea_id". $CKEditor->replace ("news_content"); >


Introduce plug-in method two:
First, let's say, we're going to use the Zend framework stuff. We extracted the Zend framework into the prtected/vendors, and now the folder is protected/vendors/zend/search/lucene.php

Second, in the head of the controller file, insert the following code.
Yii::import (' application.vendors.* ');
Require once (' zend/search/lucene.php ');
The above code contains the Lucene.php class file. Because we are using a relative path, we need to change the path of the PHP load file, Yii::import must be before require_once.

Thirdly, once we've set it up, we can use it in the controller. For example
$lucene =new Zend Search lucene ($pathOfIndex);
$hits = $lucene->find (strtolower ($keyword));



Iv. Introduction of any other file in one page
For example, want to be in. /controllers/outsourcecontroller.php Direct use: /components/rmsclient.php, you can use the following methods
Require_once (DirName (__file__). " /.. /components/rmsclient.php "),///Note the following method is introduced, the promotion cannot find Require_once (Yii::app ()->baseurl. "/protected/components/rmsclient.php");//reason: Include, require contains the file path on the server, and the URL is not directly related. If you want to use the Yii::app () method, you can: The Yii::app ()->basepath in/config/main.php.


  • 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.