Closed agussudarmanto closed 6 years ago
Hello! Generating a module through gii in this template is no different from the standard, it is important to specify the correct data. https://www.yiiframework.com/doc/guide/2.0/en/start-gii
The module will be generated in the modules directory of the root directory: https://github.com/Dominus77/yii2-advanced-start/tree/master/modules
Usage: backend/config/main.php https://github.com/Dominus77/yii2-advanced-start/blob/826bb3aed5622c27a0620edac8e2d2f562944313/backend/config/main.php#L17 https://github.com/Dominus77/yii2-advanced-start/blob/826bb3aed5622c27a0620edac8e2d2f562944313/backend/config/main.php#L22-L24 common/config/main.php https://github.com/Dominus77/yii2-advanced-start/blob/826bb3aed5622c27a0620edac8e2d2f562944313/common/config/main.php#L11-L13 frontend/config/main.php https://github.com/Dominus77/yii2-advanced-start/blob/826bb3aed5622c27a0620edac8e2d2f562944313/frontend/config/main.php#L43
That's it, the module will be available http://mysite.com/example/default/index
and http://mysite.com/admin/example/default/index
URL depends on the specified rules in the Bootstrap.php file https://github.com/Dominus77/yii2-advanced-start/blob/826bb3aed5622c27a0620edac8e2d2f562944313/modules/main/Bootstrap.php#L30-L31
The rules for the module can be for example:
'example' => 'example/default/index',
'example/<_a:[\w\-]+>' => 'example/default/<_a>',
And then the URL will be as follows:
http://mysite.com/example
http://mysite.com/admin/example
Here so, in general terms)
http://yii2-advanced-start.loc/gii/module
Module Class: modules\example\Module Module ID: example
Click Preview and Generate
modules\example\Bootstrap.php
<?php
namespace modules\example;
use Yii;
/**
* Class Bootstrap
* @package modules\example
*/
class Bootstrap
{
public function __construct()
{
// If there is support for i18n then we set up here
$i18n = Yii::$app->i18n;
$i18n->translations['modules/example/*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@modules/example/messages',
'fileMap' => [
'modules/example/module' => 'module.php',
],
];
// Rules of routing here
$urlManager = Yii::$app->urlManager;
$urlManager->addRules(
[
// Declaration of rules here
'example' => 'example/default/index',
'example/<_a:[\w\-]+>' => 'example/default/<_a>',
]
);
}
}
return [
//...
'bootstrap' => [
'modules\example\Bootstrap',
],
'modules' => [
//...
'example' => [
'class' => 'modules\example\Module',
],
],
//...
];
http://yii2-advanced-start.loc/example
http://yii2-advanced-start.loc/admin/example
Done!
Other connections and organization of modules can be viewed already in the installed ones.
Thank`s a lot sir, Its really great works
Hi Sir, I wants to add new module, is there any tutorial for that, if any i appreciate step-by-step tutorial, because i was use
gii
inside backend to generate modules and add inconfig/main.php
, but it can't run and show 404.Thanks for your answer sir.