如Yii文件中所述
导入课程或目录。
导入类就像包含相应的类文件一样。该 主要区别在于导入类更轻,因为它 仅在第一个引用类时包含类文件 时间。
导入目录相当于在PHP中添加目录 包括路径。如果导入了多个目录,则为目录 稍后导入将优先于类文件搜索(即, 它们被添加到PHP包含路径的前面。)
请考虑以下代码段:
Yii::import('application.components.document');
echo "This is included file:";
foreach(get_included_files() as $value){
echo "<div>".$value."</div>";
}
这是一个输出:
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
但是这个类在我使用它之后导入了Yii::app()->document;
。