How to create a module in yii2 and setting up the same on configuration. I've been searching a while on google and I cannot find that much tutorial on it. Please help.
See Question&Answers more detail:osHow to create a module in yii2 and setting up the same on configuration. I've been searching a while on google and I cannot find that much tutorial on it. Please help.
See Question&Answers more detail:osOption 1
Create a modules folder on your application base path. This would be what corresponds to your @app
alias of your currently running application. This is the same as the root folder of basic template or backend/frontend in the advanced template.
Inside your modules folder create a folder for your module corresponding to the Module ID.
Your Module Class should be inside this module folder and should extend yiiaseModule
. This is a basic working example for your module class.
<?php
namespace appmoduleshome;
class Home extends yiiaseModule
{
public $controllerNamespace = 'appmoduleshomecontrollers';
public function init()
{
parent::init();
// custom initialization code goes here
}
}
Create your module controller, models and views folder on the same folder.
To access the module, you need to add this to your application configuration:
<?php
......
'modules' => [
'home' => [
'class' => 'appmoduleshomeHome',
],
],
......
Option 2
If you are using Gii module, go to module generator and enter path to module class. This would be the same as appmoduleshomeHome
in option
1
Preview and Generate all files. Change application configuration as in Option 1 according to your module class.