PHP code example of mitisk / yii2-admin

1. Go to this page and download the library: Download mitisk/yii2-admin 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/ */

    

mitisk / yii2-admin example snippets


'modules' => [
    'admin' => [
        'class' => 'Mitisk\Yii2Admin\Module',
        //'layout' => 'admin', // Используемый лейаут
    ],
    // ...
],

'components' => [
    'settings' => [
        'class' => 'Mitisk\Yii2Admin\components\SettingsComponent',
    ],
    // ...
],

// Сохранить настройку
Yii::$app->settings->set('Mitisk\Yii2Admin\models\Settings', 'api_key', 'your-key');

// Получить настройку
$apiKey = Yii::$app->settings->get('Mitisk\Yii2Admin\models\Settings', 'api_key');

'components' => [
    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'suffix' => '/',
        'normalizer' => [
            'class' => 'yii\web\UrlNormalizer',
            'normalizeTrailingSlash' => true,
            'collapseSlashes' => true,
        ],
        'rules' => [
            '/' => 'site/index',
        ]
        //'rules' => 

'components' => [
    'formatter' => [
        'class' => yii\i18n\Formatter::class,
        'locale' => 'ru-RU',
        'timeZone' => 'Europe/Moscow',
        'defaultTimeZone' => 'UTC',
        'dateFormat' => 'php:d MMMM Y',
        'timeFormat' => 'php:H:i:s',
        'datetimeFormat' => 'php:d MMMM Y H:i:s',
        'decimalSeparator' => ',',
        'thousandSeparator' => ' ',
        'currencyCode' => 'RUR',
    ],
    // ...
],

'bootstrap' => ['log', 'admin'],

use Mitisk\Yii2Admin\widgets\MenuWidget;

Yii::$app->on(MenuWidget::EVENT_BEFORE_RENDER, function ($event) {
    $event->menuArray[] = [
        'label' => 'Новый пункт',
        'href' => '/new-item',
        'icon' => 'icon-name'
    ];
});

$mailService = new \Mitisk\Yii2Admin\components\MailService();
$mailService->send('template_slug', '[email protected]', [
    'PARAM1' => 'Value 1',
    'PARAM2' => 'Value 2',
]);

'components' => [
    'seo' => [
        'class' => 'Mitisk\Yii2Admin\components\SeoManager',
    ],
    // ...
],

// В layout (например, views/layouts/main.php), перед <!DOCTYPE html>:
Yii::$app->seo->register();

// В экшене контроллера:
Yii::$app->seo->setContext([
    'category_name' => $category->name,
    'count' => $dataProvider->getTotalCount(),
    'brand' => $brand->title,
]);
bash
php yii migrate --migrationPath=@vendor/mitisk/yii2-admin/migrations