PHPackages                             itstructure/yii2-admin-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. itstructure/yii2-admin-module

ActivePackage[Admin Panels](/categories/admin)

itstructure/yii2-admin-module
=============================

Admin module for Yii2 Framework with AdminLTE template

1.8.8(7mo ago)61.3k4MITPHPPHP &gt;=7.1.0

Since Feb 13Pushed 7mo agoCompare

[ Source](https://github.com/itstructure/yii2-admin-module)[ Packagist](https://packagist.org/packages/itstructure/yii2-admin-module)[ RSS](/packages/itstructure-yii2-admin-module/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (8)Dependencies (4)Versions (29)Used By (0)

Yii2 Admin module
=================

[](#yii2-admin-module)

[![Latest Stable Version](https://camo.githubusercontent.com/25a739c6f026aec9e48e7b3ed7d78999932989e80930701d9f500a15c7f753ca/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d61646d696e2d6d6f64756c652f762f737461626c65)](https://packagist.org/packages/itstructure/yii2-admin-module)[![Latest Unstable Version](https://camo.githubusercontent.com/d7a43c5501473f5c6af43c4b6da0b0d42f2fe98373a76c75d162b5d404919ced/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d61646d696e2d6d6f64756c652f762f756e737461626c65)](https://packagist.org/packages/itstructure/yii2-admin-module)[![License](https://camo.githubusercontent.com/f69582ddde7d1254968386e2c459838f50bca34a6637aef7691ebfc725aba2f1/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d61646d696e2d6d6f64756c652f6c6963656e7365)](https://packagist.org/packages/itstructure/yii2-admin-module)[![Total Downloads](https://camo.githubusercontent.com/8024ce03501b1a5a2ed011648d4ecdfcad84533aceb345e0d20ef9403ad61b0c/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d61646d696e2d6d6f64756c652f646f776e6c6f616473)](https://packagist.org/packages/itstructure/yii2-admin-module)[![Build Status](https://camo.githubusercontent.com/620ec5228aaf3de1c60a23514aba7edb99b9bc06f7f1daab813ff35ccd0fd23f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f69747374727563747572652f796969322d61646d696e2d6d6f64756c652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/itstructure/yii2-admin-module/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0c3aea8628f65e52cd02879f5dc2d8b131dbb39ded0d7551b2dbc3b064bcf269/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f69747374727563747572652f796969322d61646d696e2d6d6f64756c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/itstructure/yii2-admin-module/?branch=master)

Introduction
------------

[](#introduction)

**Yii2AdminModule** -- Module for the Yii2 v2.0.x framework with [AdminLTE](https://github.com/ColorlibHQ/AdminLTE) v2.4 template, which provides the following options:

- Use this module as base administrator dashboard to manage site content with the ability to extend it by children application CRUD's
- Work in multilanguage mode for content
- Work in multilanguage mode for dashboard

Module functional block scheme:

[![Admin module scheme](https://github.com/itstructure/yii2-admin-module/raw/master/admin_module_scheme.jpg)](https://github.com/itstructure/yii2-admin-module/blob/master/admin_module_scheme.jpg)

Note!!!

As this module gives you a freedom in the architecture of your application child classes, pay attention:

- There are no the next specific entity model classes, which are as examples in documentation: `Catalog`, `CatalogLanguage` - you have to create them personally in your application.
- There are no the next specific controller class, which is as example in documentation: `CatalogController` - you have to create it personally in your application.
- There are not routes - you have to create that according with your application controller map.

Base project example, which uses this admin module for multilanguage content and dashboard: [yii2-template-multilanguage](https://github.com/itstructure/yii2-template-multilanguage).

Base project example, which uses this admin module for simple data: [yii2-template-simple](https://github.com/itstructure/yii2-template-simple).

Addition module description you can see in my [Personal site](https://pack-develop.info/en/product/yii2-admin-module).

Dependencies
------------

[](#dependencies)

- php &gt;= 7.1
- composer 2

Installation
------------

[](#installation)

Via composer:

`composer require itstructure/yii2-admin-module ~1.8.8`

Usage
-----

[](#usage)

### Main properties

[](#main-properties)

The **name** of module: `admin`

The **namespace** for used classes: `Itstructure\AdminModule`.

The **alias** to access in to module root directory: `@admin`.

The main module template **layout** is in: `@admin/views/layouts/main-admin.php`.

### Application config

[](#application-config)

Base application config must be like in example below:

```
use Itstructure\AdminModule\Module;
use Itstructure\AdminModule\components\AdminView;
```

```
'modules' => [
    'admin' => [
        'class' => Module::class,
        'viewPath' => '@app/views/admin',
        'controllerMap' => [
            'catalog' => CatalogController::class,
        ],
        'accessRoles' => ['admin', 'manager'],
        'components' => [
            'view' => [
                'class' => AdminView::class,
                'skin' => AdminView::SKIN_GREEN_LIGHT,
                'bodyLayout' => AdminView::LAYOUT_SIDEBAR_MINI,
                'mainMenuConfig' => require __DIR__ . '/main-menu.php'
                'extraAssets' => require __DIR__ . '/extra-assets.php',
            ],
        ],
    ],
],
```

Here,

`viewPath` - view template location for CRUDs, which you will create in application.

`CatalogController` - example controller.

`accessRoles` - an array of roles, that are allowed to access. Bu default `['@']`.

in `components` the `view` component contains required parameter `class`. Such parameters as `skin`, `bodyLayout` - dashboard style, can be set custom.

Parameter `mainMenuConfig` - is the sidebar admin menu, which must be an array:

```
[
    'menuItems' => [
        'catalog' => [
            'title' => 'Catalog',
            'icon' => 'fa fa-database',
            'url' => '#',
            'subItems' => [
                'subitem' => [
                    'title' => 'Subcatalog',
                    'icon' => 'fa fa-link',
                    'url' => '/admin/catalog',
                ]
            ]
        ],
        'otheritem' => [
            'title' => 'Other Item',
            'icon' => 'fa fa-database',
            'url' => '/admin/otheritem',
        ],
    ],
]
```

Parameter `extraAssets` - extra assets, can be like in examples:

- Like a class names

    ```
    [
        FirstExtraAsset::class,
        SecondExtraAsset::class,
    ]
    ```
- Or like an array config

    ```
    [
        [
            'class' => FirstExtraAsset::class,
        ],
        [
            'class' => SecondExtraAsset::class,
        ],
    ]
    ```

### Base controllers

[](#base-controllers)

In **Yii2AdminModule** there are two controllers, which can be used by child application controllers:

- `AdminController`

    When using this controller, a class AdminView will be loaded with its assets. This is done using getView() method, which in turn is taken from **module** class with getting the **view** component.
- `CommonAdminController`

    This controller extends `AdminController`. There are already created universal basic methods for child application controllers:

    - `actionIndex()`;
    - `actionView($id)`;
    - `actionCreate()`;
    - `actionUpdate($id)`;
    - `actionDelete($id)`;

    In order for the child application controller to work with the CommonAdminController, it is necessary to define the functions in child controller:

    - `getModelName()`; Sets the name of main model class.
    - `getSearchModelName()`; - Sets the name of main search model class.

    In CommonAdminController there are the next interesting options:

    - `viewCreated` - to view the record after it's creation instead all record list.
    - `additionFields` - array of addition fields with heir values for the view template.
    - `additionAttributes` - array of addition attributes with their values for current model, which can be set in model except for those that are sent from the form. Example: information about the uploaded file, which was uploaded separate from the main send from the form.

### Integrated controllers

[](#integrated-controllers)

In **Yii2AdminModule** there is one integrated controller:

- `LanguageController` - to manage just languages for application data.

### Multilanguage mode for dashboard tools

[](#multilanguage-mode-for-dashboard-tools)

Multilanguage mode just for dashboard you can set by `language` parameter in app configuration: `en-US`, `ru-RU` e.t.c.

### Multilanguage mode for data

[](#multilanguage-mode-for-data)

There is an opportunity to set modes by application configuration, using parameter:

- `isMultilanguage` - work in multilanguage mode just for content.

    When **true**, the sidebar link "Languages" in main menu will appear automatically.

And application configuration will take an appearance:

```
use Itstructure\AdminModule\Module;
use Itstructure\AdminModule\components\AdminView;
```

```
'modules' => [
    'admin' => [
        'class' => Module::class,
        'viewPath' => '@app/views/admin',
        'controllerMap' => [
            'catalog' => CatalogController::class,
        ],
        ...
        ...
        'isMultilanguage' => true,
    ],
],
```

In multilanguage mode, such a standard is adopted:

1. All multilanguage fields will be with a language postfix:

    **title\_en**

    **description\_en**, e t. c.
2. Single and multilanguage fields will be rendered in view template by spectial fields widget.
3. All fields values after form sending will be loaded to the **MultilanguageValidateModel** by **MultilanguageValidateComponent** in **CommonAdminController**.
4. Then **MultilanguageValidateModel** will load validated values in to the main model.
5. In **main model** the field values will be processed by **MultilanguageTrait** to separate their between own **main model** and **translate model**.
6. As a model in view template, it will the **MultilanguageValidateModel**, that is set by **MultilanguageValidateComponent** in **CommonAdminController**.
7. Rules configuration for multilanguage fields validation need to be set in individual component config.
8. Rules configuration for single fields validation need to be set in the main model.
9. All the above configurations will be combined in **MultilanguageValidateModel** for general process.

**To use this mode it's necessary:**

1. Set module parameter `isMultilanguage` on **true** in application config section **mdules** -&gt; **admin**.
2. Apply module migration: `migrations/multilanguage/m171202_104405_create_language_table`

    For that make next, **if not already done**:

    - Define **admin module** in application **console** config file:

        ```
        use Itstructure\AdminModule\Module;
        ```

        ```
        'modules' => [
            'admin' => [
                'class' => Module::class,
            ],
        ],
        ```
    - In file **yii**, that is located in application root directory, set **@admin** alias:

        ```
        $application = new yii\console\Application($config);

        \Yii::setAlias('@admin', $application->getModule('admin')->getBasePath());

        $exitCode = $application->run();
        ```

        OR

        ```
        use Itstructure\AdminModule\Module;
        ```

        ```
        $application = new yii\console\Application($config);

        \Yii::setAlias('@admin', Module::getBaseDir());

        $exitCode = $application->run();
        ```
    - Run command in console:

        `yii migrate --migrationPath=@admin/migrations/multilanguage`
    - Check if the sidebar link to manage languages is appeared.
3. Application migrations must be extended from `Itstructure\AdminModule\components\MultilanguageMigration`

    It's necessary to automatically creation main table and translate table.
4. Data base tables will have a structure, like in example:

    `Main table "catalog"`

    ```
     | id | order |      created_at     |      updated_at     |
     |----|-------|---------------------|---------------------|
     | 1  |   2   | 2018-01-14 18:06:33 | 2018-01-14 18:06:33 |
     | 2  |   1   | 2018-01-14 18:10:00 | 2018-01-14 18:10:00 |
     | 3  |   3   | 2018-01-14 19:05:15 | 2018-01-14 19:05:15 |

    ```

    `Translate table "catalog_language"`

    ```
     | catalog_id | language_id |   title   |      description     |      created_at     |      updated_at     |
     |------------|-------------|-----------|----------------------|---------------------|---------------------|
     |      1     |      1      | Catalog 1 |     Description 1    | 2018-01-14 18:06:33 | 2018-01-14 18:06:33 |
     |      1     |      2      | Каталог 1 |     Описание 1       | 2018-01-14 18:06:33 | 2018-01-14 18:06:33 |
     |      2     |      1      | Catalog 2 |     Description 2    | 2018-01-14 18:10:00 | 2018-01-14 18:10:00 |
     |      3     |      1      | Catalog 3 |     Description 3    | 2018-01-14 19:05:15 | 2018-01-14 19:05:15 |
     |      3     |      2      | Каталог 3 |     Описание 3       | 2018-01-14 19:05:15 | 2018-01-14 19:05:15 |

    ```

    `Language table "language"`

    ```
     | id | locale | shortName |  name   | default |      created_at     |      updated_at     |
     |----|--------|-----------|---------|---------|---------------------|---------------------|
     | 1  | en-US  |    en     | English |    1    | 2018-01-14 18:06:33 | 2018-01-14 18:06:33 |
     | 2  | ru-RU  |    ru     | Русский |    0    | 2018-01-14 18:10:00 | 2018-01-14 18:10:00 |

    ```

    Here,

    Not multilanguage fields: **id**, **order**.

    Multilanguage fields: **title**, **description**.
5. For all described tables above, it is necessary to create CRUD model classes, like in exemple:

    **Catalog** - main model

    **CatalogLanguage** - translate model

    **Language** - **already exists in module!**
6. In child application admin controller define function getModelName(), like in example:

    ```
    protected function getModelName():string
    {
        return Catalog::class;
    }
    ```
7. In child application admin controller define function getSearchModelName(), like in example:

    ```
    protected function getSearchModelName():string
    {
        return CatalogSearch::class;
    }
    ```
8. In main model, use trait, like in example:

    ```
    use Itstructure\AdminModule\models\MultilanguageTrait;

    class Catalog extends ActiveRecord
    {
        use MultilanguageTrait;
    ...
    ```

    Using this trait, the multilanguage fields values, that are set like for example **title\_en**, **description\_en**, will be redirected to the translate model automatically.

    Not multilanguage fields, such as **order** e. t. c., will be set in to the main model automatically.
9. To display form fields in view templates use special widget (installed by composer.json dependency):

    ```
    use Itstructure\FieldWidgets\Fields.php;
    ```

    as in example:

    ```
    $form = ActiveForm::begin();
    ```

    ```
    echo Fields::widget([
        'fields' => [
            [
                'name' => 'title',
                'type' => FieldType::FIELD_TYPE_TEXT,
            ],
            [
                'name' => 'description',
                'type' => FieldType::FIELD_TYPE_TEXT_AREA,
            ],
        ],
        'model'         => $model,
        'form'          => $form,
        'languageModel' => new Language()
    ])
    ```

    ```
    Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary'])
    ```

    ```
    ActiveForm::end();
    ```

    Here,

    - **Language** - is a class in `Itstructure\AdminModule\models\Language.php`
    - This widget (when for example two languages **ru** and **en**) will parse the form fields so:

        title\_en

        title\_ru

        description\_en

        description\_ru
    - if do not set the attribute **languageModel**, form fields will not be multilanguage and will be single.
    - **$model** - will be set automatically in **CommonAdminController** as object of `Itstructure\AdminModule\models\MultilanguageValidateModel`, in which the main model can be set after define her class name by method **getModelName()**.
10. Configure the multilanguage component `multilanguage-validate-component` for **admin** module with rules for validation multilanguage data in application config, like in example:

    ```
    use Itstructure\AdminModule\Module;
    use Itstructure\AdminModule\components\AdminView;
    use Itstructure\AdminModule\components\MultilanguageValidateComponent;
    ```

    ```
    'modules' => [
        'admin' => [
            'class' => Module::class,
            'viewPath' => '@app/views/admin',
            'controllerMap' => [
                'catalog' => CatalogController::class,
                ...
            ],
            'isMultilanguage' => true,
            'components' => [
                'view' => [
                    'class' => AdminView::class,
                    'skin' => AdminView::SKIN_GREEN_LIGHT,
                    'bodyLayout' => AdminView::LAYOUT_SIDEBAR_MINI,
                    'mainMenuConfig' => require __DIR__ . '/main-menu.php'
                ],
                'multilanguage-validate-component' => [

                    /**
                     * Component class.
                     */
                    'class' => MultilanguageValidateComponent::class,

                    /**
                     * List of models.
                     * Each model is identified by the name of the table.
                     * In the config attributes of each model, you need to specify:
                     * Dynamic (translated fields) dynamicFields.
                     * Field dynamicFields needs to have: 'name' - field name.
                     * Field dynamicFields (not necessary) may have 'rules'.
                     */
                    'models' => [
                        Catalog::tableName() => [
                            'dynamicFields' => [
                                [
                                    'name' => 'title',
                                    'rules' => [
                                        [
                                            'required',
                                            'message' => 'Field "{attribute}" must not be empty.'
                                        ],
                                        [
                                            'string',
                                            'max' => 255,
                                        ],
                                        [
                                            'unique',
                                        ]
                                    ]
                                ],
                                [
                                    'name' => 'description',
                                    'rules' => [
                                        [
                                            'required',
                                            'message' => 'Field "{attribute}" must not be empty.'
                                        ],
                                        [
                                            'string',
                                        ]
                                    ]
                                ],
                            ],
                        ]
                    ]
                ]
            ],
        ]
    ]
    ```

**Useful feature:**

After release 1.6.2 in `MultilanguageValidateModel` class the **mainModelAttributes()** method checking is added to check its presence in main model. This may be necessary when you need to validate fields that are not in the database table. These fields can be set in this method, in addition to the main fields. The method must return an array.

License
-------

[](#license)

Copyright © 2018-2025 Andrey Girnik .

Licensed under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE.txt for details.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance65

Regular maintenance activity

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~103 days

Recently: every ~411 days

Total

28

Last Release

211d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31563329?v=4)[Andrey Girnik](/maintainers/itstructure)[@itstructure](https://github.com/itstructure)

---

Top Contributors

[![itstructure](https://avatars.githubusercontent.com/u/31563329?v=4)](https://github.com/itstructure "itstructure (29 commits)")

---

Tags

admindashboardmodulemultilanguagemultilanguage-fieldsyii2yii2-adminyii2-frameworkyii2-templateyii2moduledashboardadminyii 2

### Embed Badge

![Health badge](/badges/itstructure-yii2-admin-module/health.svg)

```
[![Health](https://phpackages.com/badges/itstructure-yii2-admin-module/health.svg)](https://phpackages.com/packages/itstructure-yii2-admin-module)
```

###  Alternatives

[dmstr/yii2-adminlte-asset

AdminLTE backend theme asset bundle for Yii 2.0 Framework

1.1k1.8M67](/packages/dmstr-yii2-adminlte-asset)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
