Mario Shtika
Mario Shtika

Reputation: 1486

Yii2 Modules in advanced template

I want to create a module (for example Users) in an advanced template application, that I could use it both in the backend (CRUD functionality) and frontend (login, profile)

Which is the right way of doing it, without having to create one module in backend and another in frontend and maybe a model in the common folder?

I want all files in one folder.

Upvotes: 2

Views: 2076

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133370

The simplest way for for create a module that you can use both backend and frontend and easily reusable also in other project is create the module in a your vendor dir eg:

  vendor\yourvendorname\modulename\Module.php 

then create the necessary dir

   vendor\yourvendorname\modulename\controllers
   vendor\yourvendorname\modulename\models
   vendor\yourvendorname\modulename\views

the module name in module section config\main.php

'modules' => [  

 ...

     'modulename' => [ // dfenx module for migration via web without console command
        'class' => 'vendor\youvendorname\yourmodulename\Module',
    ],

then refer to the module in you url eg:

  yourprojectname/backend/web/index.php/modulename/controller

you can refer to this guide for tutorial

Upvotes: 1

Related Questions