Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top