it-yakutia/yii2-materialadmin

Yii2 的 Material Admin 模块

安装: 293

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

语言:JavaScript

类型:yii2-extension

v1.0.7 2023-02-26 04:23 UTC

This package is auto-updated.

Last update: 2024-09-26 07:29:08 UTC


README

Yii2 的 Material Admin 模块

安装

安装此扩展的首选方式是通过 composer

可以运行

php composer.phar require --prefer-dist it-yakutia/yii2-materialadmin "*"

或者添加

"it-yakutia/yii2-materialadmin": "*"

到您的 composer.json 文件的 require 部分。

使用方法

扩展安装完成后,只需将其添加到您的 backend 配置

    ...
    'layoutPath' => '@vendor/it-yakutia/yii2-materialadmin/src/views/layouts',
    'components' => [
        ...
    ],

扩展安装完成后,使用此 SiteControllerbackend

/**
 * Site controller
 */
class SiteController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => ['login', 'error'],
                        'allow' => true,
                    ],
                    [
                        'actions' => ['logout', 'index'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
                'layout' => 'empty'
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return string
     */
    public function actionIndex()
    {
        return $this->render('index');
    }

    public function actionLogin()
    {
        return $this->redirect(['/materialadmin/profile/login']);
    }
}

扩展安装完成后,只需将其添加到您的 console 配置

    'controllerMap' => [
        ...
        'faker' => [
            'class' => \ityakutia\materialadmin\commands\FakerController::class,
        ],
        'migrate' => [
            'class' => MigrateController::class,
            'migrationPath' => [
                ...
                '@ityakutia/materialadmin/migrations',
            ],
        ],
    ]

@backend/views/layout/_sidenav 创建自定义导航项

<?php

use yii\helpers\Url;

?>

<?php if(Yii::$app->user->can("costom_modules")) { ?>
    <li><a class="subheader grey-text"><i class="material-icons grey-text tiny">public</i> <?= Yii::t('app', 'Мои модули')?></a></li>
<?php } ?>

<?php if(Yii::$app->user->can("costom_module")) { ?>
    <li class="<?= (Yii::$app->controller->module->id=='costom_module' && Yii::$app->controller->id=='back')?'active':''; ?>"><a class="waves-effect waves-teal" href="<?= Url::toRoute('/costom_module/back/index') ?>"><i class="material-icons">pageview</i> <?= Yii::t('app', 'Мой модуль') ?></a></li>
<?php } ?>

设置自定义标志,只需将其添加到您的 backend 参数

'materialadmin_module' => [
    'custom_assets' => [
        'logo_favicon' => '/admin/images/logo_favicon.png',
        'logo_sidenav' => '/admin/images/logo_sidenav.png',
        'logo_login' => '/admin/images/logo_login.png',
    ],
],