Namespace error when using gridview using custom theme in yii2

I am new to yii2, but I have been using Yii 1.x for quite a long time. I am using advanced template of Yii2 and implementing custom theme for the backend. I am using theme for the backend. I have set up my theme as follows:

  1. Installed theme using composer

  2. Added theme support in backend/config/main.php as follows:







  1. Changed namespace app\assets; into namespace backend\assets; in backend/assets/AppAsset.php

  2. I created my theme in web folder as backend/web/themes/admin and put my views there.

  3. In my controller, to use the theme I just created, I put the following code:

$this->getView()->theme = Yii::createObject([

    'class' => '\yii\base\Theme',

    'pathMap' => ['@backend/views' => '@webroot/themes/admin/views'],

    'baseUrl' => '@web/themes/admin',


  1. The login screen works fine. But if I have any widget, suppose Gridview, then I get namespace error. The error I get is:

Unknown Class – yii\base\UnknownClassException

Unable to find 'app\assets\AppAsset' in file: D:\projects\bmjobs\site\backend/assets/AppAsset.php. Namespace missing?

  1. If I change the namespace in AppAsset.php to app\assets, then I get the following error:

    PHP Fatal Error – yii\base\ErrorException

    Call to a member function checkAccess() on a non-object

I am not sure where I went wrong. Can anybody please help me out with this?

Thanks in advance.