dongmeng9048 2014-04-17 03:51
浏览 115
已采纳

理解Yii :: import方法

As said in the Yii documentation

Imports a class or a directory.

Importing a class is like including the corresponding class file. The main difference is that importing a class is much lighter because it only includes the class file when the class is referenced the first time.

Importing a directory is equivalent to adding a directory into the PHP include path. If multiple directories are imported, the directories imported later will take precedence in class file searching (i.e., they are added to the front of the PHP include path).

Consider the following code snippet:

Yii::import('application.components.document');
echo "This is included file:";
foreach(get_included_files() as $value){
    echo "<div>".$value."</div>";
}

Here is an output:

Z:\home\localhost\www\index.php
Z:\home\localhost\www\yii\framework\yii.php
Z:\home\localhost\www\yii\framework\YiiBase.php
Z:\home\localhost\www\yii\framework\base\interfaces.php
Z:\home\localhost\www\yii\framework\web\CWebApplication.php
Z:\home\localhost\www\yii\framework\base\CApplication.php
Z:\home\localhost\www\yii\framework\base\CModule.php
Z:\home\localhost\www\yii\framework\base\CComponent.php
Z:\home\localhost\www\web-config.php
Z:\home\localhost\www\yii\framework\logging\CLogger.php
Z:\home\localhost\www\yii\framework\web\CHttpRequest.php
Z:\home\localhost\www\yii\framework\base\CApplicationComponent.php
Z:\home\localhost\www\yii\framework\collections\CMap.php
Z:\home\localhost\www\yii\framework\web\CUrlManager.php
Z:\home\localhost\www\protected\controllers\tranController.php
Z:\home\localhost\www\yii\framework\web\CController.php
Z:\home\localhost\www\yii\framework\web\CBaseController.php
Z:\home\localhost\www\protected\controllers\tranAction.php
Z:\home\localhost\www\yii\framework\web\actions\CAction.php

But this class imported after I'm using it like Yii::app()->document;.

  • 写回答

1条回答 默认 最新

  • duanou2016 2014-04-17 05:01
    关注

    function Yii::import don't include file, but simple add path to $_import array, look this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题