Question: Inside my Controller I want a function to use `mpdf` e.g.

```
public function actionPdf(){

    include("MPDF57/mpdf.php");
    $mpdf=new mPDF('c'); 
    $mpdf->SetDisplayMode('fullpage');
    $mpdf->WriteHTML("<h1>Hello World!</h1>");
    $mpdf->Output('filename.pdf', 'F');

    }

}

```

This does not work, and throws an error: 

> 
> Class 'app\controllers\mPDF' not found
> 
> 
> 

What should I do If I want to autoload the class 

(a). Just for this Controller Action

(b). To make it usable everywhere just by using the `use` statement.

I know it has to do something with `namespaces` but don't know how do I define a namespace, and where do I place this `MPDF57` folder and then make it accessible.

I also tried this : 

```
 $name = "MPDF57/mpdf.php";
spl_autoload_register(function ($name) {
    var_dump($name);
});

```

But this didn't work either. throws the same error when I call my controller Action. 

Here is the namespace declaration and `use` statements inside : 

```
namespace app\controllers;

    use Yii;
    use app\models\Regs;
    use app\models\Voters;
    use app\models\RegsSearch;
    use yii\web\Controller;
    use yii\web\NotFoundHttpException;
    use yii\filters\VerbFilter;
    use \yii\web\Response;
    use yii\helpers\Html;
    use kartik\mpdf\Pdf;

```

Answer: 
Yii has already had autoloader, you do need nothing to load your class.
Just create your class with correct namespace and it will be loaded where are you using it only.

Namspace should represent real path to PHP file. PHP file name and class name should be same.
You should simply use [mpdf/mpdf](https://packagist.org/packages/mpdf/mpdf) package :

1. Install it using composer :

`composer require "mpdf/mpdf" ">=6.0.0"`
2. Use it like this :

`$mpdf = new \mPDF();`

Or you can use a yii2 extension like this one : <https://github.com/kartik-v/yii2-mpdf>