weison-tech/yii2-adminlte-asset

Backend theme for Yii2 Framework

Installs: 220

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 425

Type:yii2-extension

2.4.4 2018-04-24 09:23 UTC

README

Latest Stable Version Total Downloads License

Backend UI for Yii2 Framework, based on AdminLTE

"Yii2 AdminLTE Presentation"

This package contains an Asset Bundle for Yii 2.0 Framework which registers the CSS files for the AdminLTE user-interface.

The CSS files are installed via Yii's recommended usage of the fxp/composer-asset-plugin v1.1.1 or later.

Installation

The preferred way to install this extension is through composer.

To install AdminLTE v2 run:

php composer.phar require weison-tech/yii2-adminlte-asset "2.*"

To install AdminLTE v1 run:

php composer.phar require weison-tech/yii2-adminlte-asset "1.*"

Quick Start

Once the extension is installed, you can have a preview by reconfiguring the path mappings of the view component:

For Yii 2 Advanced Application Template or Basic Application Template

'components' => [
    'view' => [
         'theme' => [
             'pathMap' => [
                '@app/views' => '@vendor/weison-tech/yii2-adminlte-asset/example-views/yiisoft/yii2-app'
             ],
         ],
    ],
],

For phd5 application

'components' => [
    'view' => [
        'theme' => [
            'pathMap' => [
                '@app/views' => '@vendor/weison-tech/yii2-adminlte-asset/example-views/phundament/app'
            ],
        ],
    ],
],

This asset bundle provides sample files for layout and view (see folder examples/), they are not meant to be customized directly in the vendor/ folder.

Therefore it is recommended to copy the views into your application and adjust them to your needs.

Customization

  • Copy files from vendor/weison-tech/yii2-adminlte-asset/example-views/yiisoft/yii2-app (or other theme) to @app/views.
  • Remove the custom view configuration from your application by deleting the path mappings, if you have made them before.
  • Edit your views adhering to html markup vendor/almasaeed2010/adminlte/pages

AdminLTE Plugins

Assets for AdminLTE plugins are not included in our AdminLteAsset but you can find these files in your vendor directory under vendor/almasaeed2010/adminlte/plugins. So if you want to use any of them we recommend to create a custom bundle where you list the plugin files you need:

use yii\web\AssetBundle;
class AdminLtePluginAsset extends AssetBundle
{
    public $sourcePath = '@vendor/almasaeed2010/adminlte/plugins';
    public $js = [
        'datatables/dataTables.bootstrap.min.js',
        // more plugin Js here
    ];
    public $css = [
        'datatables/dataTables.bootstrap.css',
        // more plugin CSS here
    ];
    public $depends = [
        'dmstr\web\AdminLteAsset',
    ];
}

As this asset depends on our AdminLteAsset it's the only asset you have to register, for example in your main.php layout file.

Skins

By default the extension uses blue skin for AdminLTE. You can change it in config file.

'components' => [
    'assetManager' => [
        'bundles' => [
            'dmstr\web\AdminLteAsset' => [
                'skin' => 'skin-black',
            ],
        ],
    ],
],

And then just replace class of body skin-blue. You can use AdminLteHelper::skinClass() if you don't want to alter every view file when you change skin color.

<body class="<?= \dmstr\helpers\AdminLteHelper::skinClass() ?>">

Note: Use AdminLteHelper::skinClass() only if you override the skin through configuration. Otherwise you will not get the correct css class of body.

Here is the list of available skins:

"skin-blue",
"skin-black",
"skin-red",
"skin-yellow",
"skin-purple",
"skin-green",
"skin-blue-light",
"skin-black-light",
"skin-red-light",
"skin-yellow-light",
"skin-purple-light",
"skin-green-light"

If you want to use native DOM of headers AdminLTE

<h1>
    About <small>static page</small>
</h1>

then you can follow the code:

/* @var $this yii\web\View */

$this->params['breadcrumbs'][] = 'About';

$this->beginBlock('content-header'); ?>
About <small>static page</small>
<?php $this->endBlock(); ?>

<div class="site-about">
    <p> This is the About page. You may modify the following file to customize its content: </p>
    <code><?= __FILE__ ?></code>
</div>

Left sidebar menu - Widget Menu

If you need to separate sections of the menu then just add the li.header item to items

    'items' => [
        ['label' => 'Gii', 'icon' => 'fa fa-file-code-o', 'url' => ['/gii']],
        ['label' => 'Debug', 'icon' => 'fa fa-dashboard', 'url' => ['/debug']],
        ['label' => 'MAIN NAVIGATION', 'options' => ['class' => 'header']], // here
        // ... a group items
        ['label' => '', 'options' => ['class' => 'header']],
        // ... a group items
        ['label' => '', 'options' => ['class' => 'header']],
        // ... a group items

To add a label for a item:

'items' => [
        [
            'label' => '<span>Mailbox</span><span class="pull-right-container"><small class="label pull-right bg-yellow">' . $mailCount . '</small></span>',
            'icon' => 'fa fa fa-envelope-o',
            'url' => ['/mailbox'],
            'encode' => false,
        ],

Template for Gii CRUD generator

Tell Gii about our template. The setting is made in the config file:

if (YII_ENV_DEV) {    
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',      
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],  
        'generators' => [ //here
            'crud' => [
                'class' => 'yii\gii\generators\crud\Generator',
                'templates' => [
                    'adminlte' => '@vendor/dmstr/yii2-adminlte-asset/gii/templates/crud/simple',
                ]
            ]
        ],
    ];
}

Further Information

For AdminLTE documentation, please read https://almsaeedstudio.com/themes/AdminLTE/documentation/index.html

Namespacing rules follow the Yii 2.0 framework structure, eg. dmstr\web for the Asset Bundle.