Yii Import Function


Can anyone please help me I am new to yii2 and I can’t find a replacement function for doing something like this


Yii::import statement doesn’t work under yii2 can anyone please confirm this and let me know what I can use as an alternative.

You need to use namespaces in Yii 2.0.

Also read the rest of the guide, since you are new to Yii2 and need to get familiar with terms - that are new for a Yii 1.x user.

Register your class in vendor namespace.

  1. create a class in vendor folder

namespace vendor;

class TestDoc {

    public function testit() {

        return 'working....';



  1. use the name space to call the class.

namespace app\controllers;

use yii\web\Controller;

use vendor\TestDoc;

class TestController extends Controller {

    public function actionIndex() {

        $testDocObj = new TestDoc();

        echo $testDocObj->testit();