Yii 2: module class not found

The backend / config / main file has a link to the module class:

'modules' => [
    'cropk' => [
        'class' => 'app\modules\cropk\CropK',
    ]
],

      

The following CropK class exists in the vendor / xxx / cropk directory :

namespace app\modules\cropk;

class CropK extends \yii\base\Module {

    public function init() {
        parent::init();
    }
}

      

vendor / xxx / cropk / controllers / DefaultController :

namespace app\modules\cropk\controllers;

use yii\web\Controller;

class DefaultController extends Controller {
    public function actionIndex() {
        return $this->render('index');
    }
}

      

But when I access the URL http://admin.cropk.dev/cropk I get this error:

Class app \ modules \ cropk \ CropK does not exist

Can't I put the module outside of the backend directory? How can i do this?

+3


source to share


1 answer


Normal module is indicated like this

'modules' => [
    'moduleName' => [
        'class' => 'vendor\vendorName\moduleName\Module',

      

and rename the module class to Module

and notCropk



This is an example Module.php

    /*
     *
     *  */

    namespace vendor\xxx\modulename;

    use \yii\base\Module as BaseModule;

    /**
     *
     */
    class Module extends BaseModule
    {
        public $controllerNamespace = 'vendor\xxx\modulename\controllers';

        const VERSION = '1.0.0-dev';

        public function init()
        {
            parent::init();

            // custom initialization code goes here
        }
    }

      

+5


source







All Articles