Php 理解Yii::导入方法

Php 理解Yii::导入方法,php,yii,components,Php,Yii,Components,正如Yii文件中所述 导入类或目录 导入类类似于包含相应的类文件。这个 主要区别在于导入类要轻得多,因为它 仅当类第一次被引用时才包括类文件 时间 导入目录相当于将目录添加到PHP中 包括路径。如果导入多个目录,则目录 以后导入的将优先于类文件搜索(即。, 它们被添加到PHP(包含路径)的前面 考虑以下代码段: Yii::import('application.components.document'); echo "This is included file:"; foreach(get_in

正如Yii文件中所述

导入类或目录

导入类类似于包含相应的类文件。这个 主要区别在于导入类要轻得多,因为它 仅当类第一次被引用时才包括类文件 时间

导入目录相当于将目录添加到PHP中 包括路径。如果导入多个目录,则目录 以后导入的将优先于类文件搜索(即。, 它们被添加到PHP(包含路径)的前面

考虑以下代码段:

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

但是这个类是在我使用它之后导入的,就像
Yii::app()->document

函数Yii::导入不包括文件,但只需将路径添加到$\u导入数组,请看。

谢谢您的回答。但我想澄清一件事:如果我们将组件应用为
Yii::app()->document
然后调用
\uu get
魔术方法。此方法调用
getComponent
方法,该方法使用
\u componentConfig
数组,但不使用
\u import
。那么为什么没有
Yii::import('application.components.document')我们不能使用
Yii->app()->document
组件?我想我们可以,因为我们在配置文件中指定了类组件:document=>array('class'=>'application.components.document'))
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