Question: I have an yii2 project and controller MyModelController.php there, where I want to get model

```
namespace app\controllers;
use yii\web\Controller;
use yii\db\Command;
class MyModelController extends Controller
{
    public function actionPhoto()
    {
        $model=new myModel;
        return $this->render('photo', ['model' => $model]);
    }
}

```

and model 

```
MyModel.php:
    use namespace app\models;

    use yii\base\Model;
    class MyModel extends ActiveRecord
    {
        public static function model($className=__CLASS__)
        {
            return parent::model($className);
        }
        public function tableName()
        {
            return 'my_model';
        }
        public function rules()
        {
            ... some rules
        }
        public function relations()
        {
            return array(
            );
        }
        //like fields in my table in mysql
        public function attributeLabels()
        {
            return array(
                'id' => 'ID',
                'my_model_atribute' => 'MyModel',
            );
        }

        public function search()
        {
            ... some search
        }
    }

```

They are in `/basic/models` and `/basic/controllers` respectively.

And I get this mistake when I call it in my view:

```
Class 'app\controllers\MyModel' not found

```

**UPD1**
I tried to make it in view `photo.php`

```
use yii\helpers\Html;
$model=new MyModel;
var_dump($model);

```

And I still gives mistake that class not found.
**UPD2**
I change namespace to `basic\models` and `public_html\basic\models` as it actually are but it still doesn't find class there/

Answer: 
```
    namespace basic\controllers;
    use yii\web\Controller;
    use yii\db\Command;
    class MyModelController extends Controller
    {
        public function actionPhoto()
        {
            $model=new myModel;
            return $this->render('photo', ['model' => $model]);
        }
   }

```

MyModel.php:
 use namespace basic\models;

```
use yii\base\Model;
class Model extends ActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
    public function tableName()
    {
        return 'my_model';
    }
    public function rules()
    {
        ... some rules
    }
    public function relations()
    {
        return array(
        );
    }
    //like fields in my table in mysql
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'my_model_atribute' => 'MyModel',
        );
    }

    public function search()
    {
       ... some search
    }
}

```
You will get error if your code is

```
app\controllers\MyModel

```

because your model ( MyModel ) is on folder /models/MyModel.php and with namespace app\models

so u must call with

```
use app\models\MyModel;

```

and declare it with

```
$model = new MyModel();

```

Like This

```
    namespace app\controllers;

    use yii\web\Controller;
    use yii\db\Command;

    // this to call your models with namespace
    use app\models\MyModel;

    class MyModelController extends Controller
    {
        public function actionPhoto()
        {
            // this to declare your model
            $model = new myModel();

            return $this->render('photo', ['model' => $model]);
        }
   }

```