PHP code example of mgrechanik / yii2-universal-module-sceleton

1. Go to this page and download the library: Download mgrechanik/yii2-universal-module-sceleton library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mgrechanik / yii2-universal-module-sceleton example snippets


use mgrechanik\yiiuniversalmodule\UniversalModule;

class YourModule extends UniversalModule
{

class YourModule extends UniversalModule
{
    public $frontendControllers = [
        'default',
    ];

class YourModule extends UniversalModule
{
    public $backendControllers = [
        'admin-default',
    ];

    // ...
    'modules' => [
        'yourModule' => [
            'class' => 'yourModuleNamespace\YourModule',
            'mode' => 'frontend',
        ],

return [
    'backendLayout' => '//lte/main',
    'backendControllerConfig' => [
        'as backendaccess' => [
            'class' => \yii\filters\AccessControl::class,
            'rules' => [
                [
                    'allow' => true,
                    'ips' => ['54.54.22.44'],
                    'matchCallback' => function ($rule, $action){
                        $user = \Yii::$app->user;
                        return !$user->isGuest &&
                            ($user->id == 1);
                },
                ]
            ],
        ],
    ],	
  
];

    'components' => [
	//...
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                'admin/<module:(example|omega)>-<controllersuffix>/<action:\w*>' =>
                    '<module>/admin-<controllersuffix>/<action>',
                'admin/<module:(example|omega)>-<controllersuffix>' =>
                    '<module>/admin-<controllersuffix>',
            ],
        ],	
    ],
    'modules' => [
        'example' => [
            'class' => 'modules\example\Module',
            'mode' => 'backend and frontend',
            'backendLayout' => $params['backendLayout'],
            'backendControllerConfig' => $params['backendControllerConfig'],
        ],
        'omega' => [
            'class' => 'modules\username1\omega\Module',
            'mode' => 'backend and frontend',
            'backendLayout' => $params['backendLayout'],
            'backendControllerConfig' => $params['backendControllerConfig'],
        ],        
    ], 

    'modules' => [
        'example' => [
            ...
        ],
        'omega' => [
            ...
        ],  

	'urlManager' => [
		'enablePrettyUrl' => true,
		'showScriptName' => false,
		'rules' => [
			'admin/<module:(example|omega)>-<controllersuffix>/<action:\w*>' =>
				'<module>/admin-<controllersuffix>/<action>',
			'admin/<module:(example|omega)>-<controllersuffix>' =>
				'<module>/admin-<controllersuffix>',
		],
	],

    'modules' => [
        'example' => [
            'class' => 'modules\example\Module',
            'controllerNamespace' => 'yourModuleNamespace\console\commands',
        ],
    ],

Module_directory/
   ui/                                  // User Interface of the module
      controllers/
          backend/                      // Backend controllers like the next:
            AdminDefaultController.php  
            ...
          frontend/                     // Frontend controllers like the next: 
            DefaultController.php       
            ...
      views/                            // Views for corresponding controllers 
          backend/
            admin-default/
          frontend/        
            default/
   Module.php                           // module class
function($map) { ...; return $map; }

Module_directory/
  console/
    commands/                // Directory for console commands
      HelloController.php
  Module.php

  models/
    backend/
      SomeBackendModel.php
    frontend/
      SomeFrontendModel.php	  
    SomeCommonModel.php