2017 © Pedro Peláez
 

yii2-extension yii2-metronic

Yii2 集成 Metronic 4.6 主题

image

iamok/yii2-metronic

Yii2 集成 Metronic 4.6 主题

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 25 % Grown

The README.md

yii2-metronic

version Download Issues, (*1)

Yii2 Metronic theme integration. Currently is supported the version 4.6, (*2)

Installation

The extension is in development and the only way to use this fork is through through composer., (*3)

So add it to your composer.json with this composer command:, (*4)

composer require --prefer-dist iamok/yii2-metronic

Then You've to unzip the contents of your metronic Zip theme inside the @webroot/metronic folder. Check Aliases., (*5)

You should have a folder structure like this:, (*6)

* app/
    * web/
        * metronic/
            * _documentation
            * _resources
            * _start
            * theme
            * theme_rtl

Quick Start

Edit your config/web.php configuration file and add the metronic component:, (*7)

'components' => [
    'metronic'=>[
        'class'=>'iamok\metronic\Metronic',
        'resources'=>'[path to my web]/web/metronic/assets/theme/assets',
        'style'=>\iamok\metronic\Metronic::STYLE_MATERIAL,
        'theme'=>\iamok\metronic\Metronic::THEME_LIGHT,
        'layoutOption'=>\iamok\metronic\Metronic::LAYOUT_FLUID,
        'headerOption'=>\iamok\metronic\Metronic::HEADER_FIXED,
        'sidebarPosition'=>\iamok\metronic\Metronic::SIDEBAR_POSITION_LEFT,
        'sidebarOption'=>\iamok\metronic\Metronic::SIDEBAR_MENU_ACCORDION,
        'footerOption'=>\iamok\metronic\Metronic::FOOTER_FIXED,

    ],
]

WARNING Check the "resources" key. This component field is used to locate the content of the zip theme. The component try to create a symlink to this directory inside it's folder. Eventually this may not work! In the case the link is invalid, you've to build it by yourself :), (*8)

My vendor folder looks like this:, (*9)

* app/
    * [...]
    * vendor/
        * iamok/
            * yii2-metronic/
                * assets -> symlink to /var/www/project/web/metronic/assets/theme/assets
                * builders/
                * bundles/
                * helpers/
                * layouts/
                * widgets/

I suggest also to configure the assetManager. My actual configuration is this:, (*10)

'assetManager' => [
        'linkAssets' => true,
        'bundles' => [
            'yii\web\JqueryAsset' => [
                'sourcePath' => null,   // do not publish the bundle
                'js' => [
                    '//code.jquery.com/jquery-1.11.2.min.js',  // use custom jquery
                ]
            ],

            'iamok\metronic\bundles\ThemeAsset' => [
                'addons'=>[
                    'default/login'=>[
                        'css'=>[
                            'pages/css/login-4.min.css',
                        ],
                        'js'=>[
                            'global/plugins/backstretch/jquery.backstretch.min.js',

                        ]
                    ],
                ]
            ],
        ],
    ],

In the ThemeAsset class i've added the support for addons. You can specify additional css/js for specific controller/action., (*11)

In the example is visible the way to add login-4.min.css and jquery.backstretch.min.js to the login page (in my case, the actionLogin is managed by a controller named DefaultController)., (*12)

Configuring the layout for your views is the last step., (*13)

The metronic component contains a sample layout view. I've not checked it. I'm working on my layout :), (*14)

Here is my sample views/layout/main.php:, (*15)

assetManager->getPublishedUrl($asset->sourcePath);
?>
beginPage() ?>



<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">

<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body <?= Layout::getHtmlOptions('body',['class'=>'page-container-bg-solid'],true) ?>>
beginBody() ?>

= $this->render('parts/header.php', ['directoryAsset' => $directoryAsset]) ?>




= $this->render('parts/sidebar.php', ['directoryAsset' => $directoryAsset]) ?> = $this->render('parts/content.php', ['content' => $content, 'directoryAsset' => $directoryAsset]) ?>
= $this->render('parts/footer.php', ['directoryAsset' => $directoryAsset]) ?> endBody() ?> </body> </html> endPage() ?>

Metronic theme require that you replace yii\helpers\Html with it's helper. So, you have to add a config/bootstrap.php with the following content:, (*16)

<?php
Yii::$classMap['yii\helpers\Html'] = '@vendor/iamok/yii2-metronic/helpers/Html.php';
?>

The file bootstrap.php should be loaded before the web application is created. So you need to edit your web/index.php file and adjust it, and add a require directive. The file content should look like this:, (*17)

<?php

// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/web.php');
require(__DIR__ . '/../config/bootstrap.php');
(new yii\web\Application($config))->run();

Things to notice:, (*18)

  • I've moved the rendering of the main parts to separate files (parts/*). You can build this files and add them to your project.
  • I pass everywhere the $directoryAsset variable: this contain the path to the assets. Useful to load images bundled with the metronic theme.
  • the BODY tag is managed with a Layout::getHtmlOptions(). This method is able to build all the Metronic required classes.
  • Always check to use $this->beginPage(), $this->beginBody() and relatives $this->endBody() and $this->endPage() in the proper places :)

The Versions

19/01 2018

dev-master

9999999-dev

Yii2 集成 Metronic 4.6 主题

  Sources   Download

BSD

The Requires

 

yii2 theme metronic

04/01 2018

1.0.0

1.0.0.0

Yii2 集成 Metronic 4.6 主题

  Sources   Download

BSD

The Requires

 

yii2 theme metronic