SushilB
SushilB

Reputation: 13

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 https://github.com/mithun12000/adminUI theme for the backend. I have set up my theme as follows:

  1. install theme using composer

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

    'view'=>[
        'theme'=>[
            'pathMap'=>['@app/views'=>'@webroot/themes/admin/views'],
            'baseUrl'=>'@web/themes/admin'
        ]
    ],
    
  3. Changed namespace app\assets; into namespace backend\assets; in backend/assets/AppAsset.php

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

  5. 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',
    ]);
    
  6. 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?
    

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.

Upvotes: 0

Views: 1172

Answers (1)

GAMITG
GAMITG

Reputation: 3818

you may change your pathMap in backend/config/main.php

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

Upvotes: 0

Related Questions