dlds/yii2-metronic
Composer 安装命令:
composer require dlds/yii2-metronic
包简介
Yii2 Metronic theme integration
README 文档
README
Yii2 Metronic theme integration. Currently is supported the version 4.6
Requirements
To use this extension it is required to buy own license for Metronic theme from https://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469?ref=keenthemes
Installation
The extension is in development and the only way to use this fork is through through composer.
So add it to your composer.json with this composer command:
php composer.phar require dlds/yii2-metronic dev-master
Then You've to unzip the contents of your metronic Zip theme inside the @webroot/metronic folder. Check Aliases.
You should have a folder structure like this:
- app/
- web/
- metronic/
- _documentation
- _resources
- _start
- theme
- theme_rtl
- metronic/
- web/
Quick Start
Edit your config/web.php configuration file and add the metronic component:
'components' => [
'metronic'=>[
'class'=>'dlds\metronic\Metronic',
'resources'=>'[path to my web]/web/metronic/assets/theme/assets',
'style'=>\dlds\metronic\Metronic::STYLE_MATERIAL,
'theme'=>\dlds\metronic\Metronic::THEME_LIGHT,
'layoutOption'=>\dlds\metronic\Metronic::LAYOUT_FLUID,
'headerOption'=>\dlds\metronic\Metronic::HEADER_FIXED,
'sidebarPosition'=>\dlds\metronic\Metronic::SIDEBAR_POSITION_LEFT,
'sidebarOption'=>\dlds\metronic\Metronic::SIDEBAR_MENU_ACCORDION,
'footerOption'=>\dlds\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 :)
My vendor folder looks like this:
- app/
- [...]
- vendor/
- dlds/
- yii2-metronic/
- assets -> symlink to /var/www/project/web/metronic/assets/theme/assets
- builders/
- bundles/
- helpers/
- layouts/
- widgets/
- yii2-metronic/
- dlds/
I suggest also to configure the assetManager. My actual configuration is this:
'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
]
],
'dlds\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.
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).
Configuring the layout for your views is the last step.
The metronic component contains a sample layout view. I've not checked it. I'm working on my layout :)
Here is my sample views/layout/main.php:
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use yii\helpers\Html;
use dlds\metronic\helpers\Layout;
use dlds\metronic\Metronic;
$asset = Metronic::registerThemeAsset($this);
$directoryAsset = Yii::$app->assetManager->getPublishedUrl($asset->sourcePath);
?>
<?php $this->beginPage() ?>
<!--[if IE 8]> <html lang="<?= Yii::$app->language ?>" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="<?= Yii::$app->language ?>" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<!--<![endif]-->
<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) ?>>
<?php $this->beginBody() ?>
<?= $this->render('parts/header.php', ['directoryAsset' => $directoryAsset]) ?>
<!-- BEGIN CONTAINER -->
<div class="page-container">
<?= $this->render('parts/sidebar.php', ['directoryAsset' => $directoryAsset]) ?>
<?= $this->render('parts/content.php', ['content' => $content, 'directoryAsset' => $directoryAsset]) ?>
</div>
<?= $this->render('parts/footer.php', ['directoryAsset' => $directoryAsset]) ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->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:
<?php
Yii::$classMap['yii\helpers\Html'] = '@vendor/dlds/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:
<?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:
- 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 :)
dlds/yii2-metronic 适用场景与选型建议
dlds/yii2-metronic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.08k 次下载、GitHub Stars 达 44, 最近一次更新时间为 2014 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「theme」 「yii2」 「metronic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dlds/yii2-metronic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dlds/yii2-metronic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dlds/yii2-metronic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Bootstrap 4.x base theme for SilverStripe
Lucency Theme
SCEditor, a lightweight WYSIWYG BBCode & HTML editor extension for Yii 2.0 Framework
Selectize Theme for Bootstrap 4
Laravel Admin Metronic
统计信息
- 总下载量: 14.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 46
- 点击次数: 13
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD
- 更新时间: 2014-12-30