phpyii2gii

yii2 Module class must be properly namespaced


I have duplicated /frontend folder into /api removed unnecessary code like views. And then I started to generate using gii the new module eg: v1

I got this error message when using api\modules namespace.

Module class must be properly namespaced.

enter image description here


Solution

  • You may not be aware but in the Yii2 framework there is a common/config/bootstrap.php file which holds the aliases eg: @frontend, @common

    Just add another line for the /api folder section and it would be good.

    Yii::setAlias('@common', dirname(__DIR__));
    Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');
    Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
    Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
    Yii::setAlias('@api', dirname(dirname(__DIR__)) . '/api');