{"id":14966694,"url":"https://github.com/itstructure/yii2-admin-module","last_synced_at":"2025-10-25T17:30:31.261Z","repository":{"id":56994559,"uuid":"121343047","full_name":"itstructure/yii2-admin-module","owner":"itstructure","description":"Admin module for Yii2 Framework with AdminLTE template","archived":false,"fork":false,"pushed_at":"2023-01-22T08:39:15.000Z","size":233,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-31T09:22:58.650Z","etag":null,"topics":["admin","dashboard","module","multilanguage","multilanguage-fields","yii2","yii2-admin","yii2-framework","yii2-template"],"latest_commit_sha":null,"homepage":"https://pack-develop.info/en/product/yii2-admin-module","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itstructure.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-13T05:32:30.000Z","updated_at":"2023-01-31T16:57:03.000Z","dependencies_parsed_at":"2023-02-01T02:01:10.794Z","dependency_job_id":null,"html_url":"https://github.com/itstructure/yii2-admin-module","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-admin-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-admin-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-admin-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-admin-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itstructure","download_url":"https://codeload.github.com/itstructure/yii2-admin-module/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238183622,"owners_count":19430158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["admin","dashboard","module","multilanguage","multilanguage-fields","yii2","yii2-admin","yii2-framework","yii2-template"],"created_at":"2024-09-24T13:36:48.762Z","updated_at":"2025-10-25T17:30:31.255Z","avatar_url":"https://github.com/itstructure.png","language":"PHP","readme":"# Yii2 Admin module\n\n[![Latest Stable Version](https://poser.pugx.org/itstructure/yii2-admin-module/v/stable)](https://packagist.org/packages/itstructure/yii2-admin-module)\n[![Latest Unstable Version](https://poser.pugx.org/itstructure/yii2-admin-module/v/unstable)](https://packagist.org/packages/itstructure/yii2-admin-module)\n[![License](https://poser.pugx.org/itstructure/yii2-admin-module/license)](https://packagist.org/packages/itstructure/yii2-admin-module)\n[![Total Downloads](https://poser.pugx.org/itstructure/yii2-admin-module/downloads)](https://packagist.org/packages/itstructure/yii2-admin-module)\n[![Build Status](https://scrutinizer-ci.com/g/itstructure/yii2-admin-module/badges/build.png?b=master)](https://scrutinizer-ci.com/g/itstructure/yii2-admin-module/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/itstructure/yii2-admin-module/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/itstructure/yii2-admin-module/?branch=master)\n\n## Introduction\n\n**Yii2AdminModule** -- Module for the Yii2 v2.0.x framework with [AdminLTE](https://github.com/ColorlibHQ/AdminLTE) v2.4 template, which provides the following options:\n- Use this module as base administrator dashboard to manage site content with the ability to extend it by children application CRUD's\n- Work in multilanguage mode for content\n- Work in multilanguage mode for dashboard\n\nModule functional block scheme:\n\n![Admin module scheme](https://github.com/itstructure/yii2-admin-module/blob/master/admin_module_scheme.jpg)\n\nNote!!!\n\nAs this module gives you a freedom in the architecture of your application child classes, pay attention:\n- 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.\n- There are no the next specific controller class, which is as example in documentation: `CatalogController` - you have to create it personally in your application.\n- There are not routes - you have to create that according with your application controller map.\n\nBase project example, which uses this admin module for multilanguage content and dashboard: [yii2-template-multilanguage](https://github.com/itstructure/yii2-template-multilanguage).\n\nBase project example, which uses this admin module for simple data: [yii2-template-simple](https://github.com/itstructure/yii2-template-simple).\n\nAddition module description you can see in my [Personal site](https://pack-develop.info/en/product/yii2-admin-module).\n\n## Dependencies\n\n- php \u003e= 7.1\n- composer 2\n\n## Installation\n\nVia composer:\n\n`composer require itstructure/yii2-admin-module ~1.8.8`\n\n## Usage\n\n### Main properties\n\nThe **name** of module: `admin`\n\nThe **namespace** for used classes: `Itstructure\\AdminModule`.\n\nThe **alias** to access in to module root directory: `@admin`.\n\nThe main module template **layout** is in: `@admin/views/layouts/main-admin.php`.\n\n### Application config\n\nBase application config must be like in example below:\n\n```php\nuse Itstructure\\AdminModule\\Module;\nuse Itstructure\\AdminModule\\components\\AdminView;\n```\n\n```php\n'modules' =\u003e [\n    'admin' =\u003e [\n        'class' =\u003e Module::class,\n        'viewPath' =\u003e '@app/views/admin',\n        'controllerMap' =\u003e [\n            'catalog' =\u003e CatalogController::class,\n        ],\n        'accessRoles' =\u003e ['admin', 'manager'],\n        'components' =\u003e [\n            'view' =\u003e [\n                'class' =\u003e AdminView::class,\n                'skin' =\u003e AdminView::SKIN_GREEN_LIGHT,\n                'bodyLayout' =\u003e AdminView::LAYOUT_SIDEBAR_MINI,\n                'mainMenuConfig' =\u003e require __DIR__ . '/main-menu.php'\n                'extraAssets' =\u003e require __DIR__ . '/extra-assets.php',\n            ],\n        ],\n    ],\n],\n```\n\nHere,\n\n`viewPath` - view template location for CRUDs, which you will create in application.\n\n`CatalogController` - example controller.\n\n`accessRoles` - an array of roles, that are allowed to access. Bu default `['@']`.\n\nin `components` the `view` component contains required parameter `class`.\nSuch parameters as `skin`, `bodyLayout` - dashboard style, can be set custom.\n\nParameter `mainMenuConfig` - is the sidebar admin menu, which must be an array:\n\n```php\n[\n    'menuItems' =\u003e [\n        'catalog' =\u003e [\n            'title' =\u003e 'Catalog',\n            'icon' =\u003e 'fa fa-database',\n            'url' =\u003e '#',\n            'subItems' =\u003e [\n                'subitem' =\u003e [\n                    'title' =\u003e 'Subcatalog',\n                    'icon' =\u003e 'fa fa-link',\n                    'url' =\u003e '/admin/catalog',\n                ]\n            ]\n        ],\n        'otheritem' =\u003e [\n            'title' =\u003e 'Other Item',\n            'icon' =\u003e 'fa fa-database',\n            'url' =\u003e '/admin/otheritem',\n        ],\n    ],\n]\n```\n\nParameter `extraAssets` - extra assets, can be like in examples:\n\n- Like a class names\n\n    ```php\n    [\n        FirstExtraAsset::class,\n        SecondExtraAsset::class,\n    ]\n    ```\n    \n- Or like an array config\n\n    ```php\n    [\n        [\n            'class' =\u003e FirstExtraAsset::class,\n        ],\n        [\n            'class' =\u003e SecondExtraAsset::class,\n        ],\n    ]\n    ```\n\n### Base controllers\n\nIn **Yii2AdminModule** there are two controllers, which can be used by child application \ncontrollers:\n\n- `AdminController`\n\n    When using this controller, a class AdminView will be loaded with its assets. This is done \n    using getView() method, which in turn is taken from **module** class with getting the \n    **view** component. \n\n- `CommonAdminController`\n\n    This controller extends `AdminController`.\n    There are already created universal basic methods for child application controllers:\n    - `actionIndex()`;\n    - `actionView($id)`;\n    - `actionCreate()`;\n    - `actionUpdate($id)`;\n    - `actionDelete($id)`;\n    \n    In order for the child application controller to work with the CommonAdminController, it is \n    necessary to define the functions in child controller:\n    - `getModelName()`; Sets the name of main model class.\n    - `getSearchModelName()`; - Sets the name of main search model class.\n    \n    In CommonAdminController there are the next interesting options:\n    - `viewCreated` - to view the record after it's creation instead all record list.\n    - `additionFields` - array of addition fields with heir values for the view template.\n    - `additionAttributes` - array of addition attributes with their values for current \n    model, which can be set in model except for those that are sent from the form.\n    Example: information about the uploaded file, which was uploaded separate from the main send from the form.\n\n### Integrated controllers\n\nIn **Yii2AdminModule** there is one integrated controller:\n\n- `LanguageController` - to manage just languages for application data.\n\n### Multilanguage mode for dashboard tools\n\nMultilanguage mode just for dashboard you can set by `language` parameter in app configuration: `en-US`, `ru-RU` e.t.c.\n\n### Multilanguage mode for data\n\nThere is an opportunity to set modes by application configuration, using parameter:\n\n- `isMultilanguage` - work in multilanguage mode just for content.\n\n    When **true**, the sidebar link \"Languages\" in main menu will appear automatically.\n\nAnd application configuration will take an appearance:\n\n```php\nuse Itstructure\\AdminModule\\Module;\nuse Itstructure\\AdminModule\\components\\AdminView;\n```\n\n```php\n'modules' =\u003e [\n    'admin' =\u003e [\n        'class' =\u003e Module::class,\n        'viewPath' =\u003e '@app/views/admin',\n        'controllerMap' =\u003e [\n            'catalog' =\u003e CatalogController::class,\n        ],\n        ...\n        ...\n        'isMultilanguage' =\u003e true,\n    ],\n],\n```\n\nIn multilanguage mode, such a standard is adopted:\n\n1.  All multilanguage fields will be with a language postfix:\n\n    **title_en**\n    \n    **description_en**, e t. c.\n    \n2. Single and multilanguage fields will be rendered in view template by spectial fields widget.\n\n3. All fields values after form sending will be loaded to the \n**MultilanguageValidateModel** by **MultilanguageValidateComponent** in **CommonAdminController**.\n\n4. Then **MultilanguageValidateModel** will load validated values in to the main model.\n\n5. In **main model** the field values will be processed by **MultilanguageTrait** to separate \ntheir between own **main model** and **translate model**.\n\n6. As a model in view template, it will the **MultilanguageValidateModel**, that is set by \n**MultilanguageValidateComponent** in **CommonAdminController**.\n\n7. Rules configuration for multilanguage fields validation need to be set in individual component \nconfig.\n\n8. Rules configuration for single fields validation need to be set in the main model.\n\n9. All the above configurations will be combined in **MultilanguageValidateModel** for general \nprocess.\n\n**To use this mode it's necessary:**\n\n1. Set module parameter `isMultilanguage` on **true** in application config section **mdules** -\u003e **admin**.\n\n2. Apply module migration: `migrations/multilanguage/m171202_104405_create_language_table`\n\n    For that make next, **if not already done**:\n    \n    - Define **admin module** in application **console** config file:\n    \n        ```php\n        use Itstructure\\AdminModule\\Module;\n        ```\n        \n        ```php\n        'modules' =\u003e [\n            'admin' =\u003e [\n                'class' =\u003e Module::class,\n            ],\n        ],\n        ```\n    \n    - In file **yii**, that is located in application root directory, set **@admin** alias:\n    \n        ```php\n        $application = new yii\\console\\Application($config);\n        \n        \\Yii::setAlias('@admin', $application-\u003egetModule('admin')-\u003egetBasePath());\n        \n        $exitCode = $application-\u003erun();\n        ```\n        \n        OR\n        \n        ```php\n        use Itstructure\\AdminModule\\Module;\n        ```\n        \n        ```php\n        $application = new yii\\console\\Application($config);\n        \n        \\Yii::setAlias('@admin', Module::getBaseDir());\n        \n        $exitCode = $application-\u003erun();\n        ```\n        \n    - Run command in console:\n    \n        `yii migrate --migrationPath=@admin/migrations/multilanguage`\n        \n    - Check if the sidebar link to manage languages is appeared.\n    \n3. Application migrations must be extended from \n`Itstructure\\AdminModule\\components\\MultilanguageMigration`\n\n    It's necessary to automatically creation main table and translate table.\n\n4. Data base tables will have a structure, like in example:\n\n    `Main table \"catalog\"`\n    \n        | id | order |      created_at     |      updated_at     |\n        |----|-------|---------------------|---------------------|\n        | 1  |   2   | 2018-01-14 18:06:33 | 2018-01-14 18:06:33 |\n        | 2  |   1   | 2018-01-14 18:10:00 | 2018-01-14 18:10:00 |\n        | 3  |   3   | 2018-01-14 19:05:15 | 2018-01-14 19:05:15 |\n\n    `Translate table \"catalog_language\"`\n\n        | catalog_id | language_id |   title   |      description     |      created_at     |      updated_at     |\n        |------------|-------------|-----------|----------------------|---------------------|---------------------|\n        |      1     |      1      | Catalog 1 |     Description 1    | 2018-01-14 18:06:33 | 2018-01-14 18:06:33 |\n        |      1     |      2      | Каталог 1 |     Описание 1       | 2018-01-14 18:06:33 | 2018-01-14 18:06:33 |\n        |      2     |      1      | Catalog 2 |     Description 2    | 2018-01-14 18:10:00 | 2018-01-14 18:10:00 |\n        |      3     |      1      | Catalog 3 |     Description 3    | 2018-01-14 19:05:15 | 2018-01-14 19:05:15 |\n        |      3     |      2      | Каталог 3 |     Описание 3       | 2018-01-14 19:05:15 | 2018-01-14 19:05:15 |\n\n    `Language table \"language\"`\n\n        | id | locale | shortName |  name   | default |      created_at     |      updated_at     |\n        |----|--------|-----------|---------|---------|---------------------|---------------------|\n        | 1  | en-US  |    en     | English |    1    | 2018-01-14 18:06:33 | 2018-01-14 18:06:33 |\n        | 2  | ru-RU  |    ru     | Русский |    0    | 2018-01-14 18:10:00 | 2018-01-14 18:10:00 |\n\n    Here,\n    \n    Not multilanguage fields: **id**, **order**.\n    \n    Multilanguage fields: **title**, **description**.\n\n5. For all described tables above, it is necessary to create CRUD model classes, like in exemple:\n\n    **Catalog** - main model\n    \n    **CatalogLanguage** - translate model\n    \n    **Language** - **already exists in module!**\n\n6. In child application admin controller define function getModelName(), like in example:\n\n    ```php\n    protected function getModelName():string\n    {\n        return Catalog::class;\n    }\n    ```\n\n7. In child application admin controller define function getSearchModelName(), like in example:\n\n    ```php\n    protected function getSearchModelName():string\n    {\n        return CatalogSearch::class;\n    }\n    ```\n\n8. In main model, use trait, like in example:\n\n    ```php\n    use Itstructure\\AdminModule\\models\\MultilanguageTrait;\n    \n    class Catalog extends ActiveRecord\n    {\n        use MultilanguageTrait;\n    ...\n    ```\n    \n    Using this trait, the multilanguage fields values, that are set like for example \n    **title_en**, **description_en**, will be redirected to the translate model automatically.\n    \n    Not multilanguage fields, such as **order** e. t. c., will be set in to the main model \n    automatically.\n\n9. To display form fields in view templates use special widget (installed by composer.json dependency):\n\n    ```php\n    use Itstructure\\FieldWidgets\\Fields.php;\n    ```\n    \n    as in example:\n    \n    ```php\n    $form = ActiveForm::begin();\n    ```\n    \n    ```php\n    echo Fields::widget([\n        'fields' =\u003e [\n            [\n                'name' =\u003e 'title',\n                'type' =\u003e FieldType::FIELD_TYPE_TEXT,\n            ],\n            [\n                'name' =\u003e 'description',\n                'type' =\u003e FieldType::FIELD_TYPE_TEXT_AREA,\n            ],\n        ],\n        'model'         =\u003e $model,\n        'form'          =\u003e $form,\n        'languageModel' =\u003e new Language()\n    ])\n    ```\n    \n    ```php\n    Html::submitButton($model-\u003eisNewRecord ? 'Create' : 'Update', ['class' =\u003e $model-\u003eisNewRecord ? 'btn btn-success' : 'btn btn-primary'])\n    ```\n    \n    ```php\n    ActiveForm::end();\n    ```\n    \n    Here,\n    \n    - **Language** - is a class in `Itstructure\\AdminModule\\models\\Language.php`\n    \n    - This widget (when for example two languages **ru** and **en**) will parse the form fields so:\n    \n        title_en\n        \n        title_ru\n        \n        description_en\n        \n        description_ru\n    \n    - if do not set the attribute **languageModel**, form fields will not be multilanguage and \n    will be single.\n    \n    - **$model** - will be set automatically in **CommonAdminController** as object of \n    `Itstructure\\AdminModule\\models\\MultilanguageValidateModel`, in which the main model can \n    be set after define her class name by method **getModelName()**.\n\n10. Configure the multilanguage component `multilanguage-validate-component` for **admin** module with rules for validation \nmultilanguage data in application config, like in example:\n\n    ```php\n    use Itstructure\\AdminModule\\Module;\n    use Itstructure\\AdminModule\\components\\AdminView;\n    use Itstructure\\AdminModule\\components\\MultilanguageValidateComponent;\n    ```\n\n    ```php\n    'modules' =\u003e [\n        'admin' =\u003e [\n            'class' =\u003e Module::class,\n            'viewPath' =\u003e '@app/views/admin',\n            'controllerMap' =\u003e [\n                'catalog' =\u003e CatalogController::class,\n                ...\n            ],\n            'isMultilanguage' =\u003e true,\n            'components' =\u003e [\n                'view' =\u003e [\n                    'class' =\u003e AdminView::class,\n                    'skin' =\u003e AdminView::SKIN_GREEN_LIGHT,\n                    'bodyLayout' =\u003e AdminView::LAYOUT_SIDEBAR_MINI,\n                    'mainMenuConfig' =\u003e require __DIR__ . '/main-menu.php'\n                ],\n                'multilanguage-validate-component' =\u003e [\n            \n                    /**\n                     * Component class.\n                     */\n                    'class' =\u003e MultilanguageValidateComponent::class,\n            \n                    /**\n                     * List of models.\n                     * Each model is identified by the name of the table.\n                     * In the config attributes of each model, you need to specify:\n                     * Dynamic (translated fields) dynamicFields.\n                     * Field dynamicFields needs to have: 'name' - field name.\n                     * Field dynamicFields (not necessary) may have 'rules'.\n                     */\n                    'models' =\u003e [\n                        Catalog::tableName() =\u003e [\n                            'dynamicFields' =\u003e [\n                                [\n                                    'name' =\u003e 'title',\n                                    'rules' =\u003e [\n                                        [\n                                            'required',\n                                            'message' =\u003e 'Field \"{attribute}\" must not be empty.'\n                                        ],\n                                        [\n                                            'string',\n                                            'max' =\u003e 255,\n                                        ],\n                                        [\n                                            'unique',\n                                        ]\n                                    ]\n                                ],\n                                [\n                                    'name' =\u003e 'description',\n                                    'rules' =\u003e [\n                                        [\n                                            'required',\n                                            'message' =\u003e 'Field \"{attribute}\" must not be empty.'\n                                        ],\n                                        [\n                                            'string',\n                                        ]\n                                    ]\n                                ],\n                            ],\n                        ]\n                    ]\n                ]\n            ],\n        ]\n    ]\n    ```\n\n**Useful feature:**\n\nAfter release 1.6.2 in `MultilanguageValidateModel` class the **mainModelAttributes()** method checking is added to check its presence in main model.\nThis 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.\n\n## License\n\nCopyright © 2018-2025 Andrey Girnik girnikandrey@gmail.com.\n\nLicensed under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE.txt for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitstructure%2Fyii2-admin-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitstructure%2Fyii2-admin-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitstructure%2Fyii2-admin-module/lists"}