4

In the backend/config/main file, there is a reference to the module class:

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

In the vendor/xxx/cropk directory, there is the following class CropK:

namespace app\modules\cropk;

class CropK extends \yii\base\Module {

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

The 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 that?

felipe.zkn
  • 2,012
  • 7
  • 31
  • 63
  • When the module was in the **backend/modules**, it was working. As I wish to create a more generic module, I have transferred the entire module to the **vendor/xxx** directory. – felipe.zkn Jun 16 '15 at 15:42

1 Answers1

7

Normaly the module is indicated in this way

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

and rename your module class in Module and not Cropk

This is a sample of 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
        }
    }
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107