funayaki / adminlte
CakePHP 的 AdminLTE 主题
Requires
- php: >=5.5.9
- cakephp/cakephp: ~3.2
- gourmet/knp-menu: ~0.4
- symfony/yaml: ~3.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-15 05:44:49 UTC
README
需求
- cakephp-adminlte-theme(https://github.com/funayaki/cakephp-adminlte-theme)
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方法是
composer require funayaki/adminlte
安装依赖项
目前此主题使用 NPM 安装外部依赖项,如 bootstrap、fontawesome 或 AdminLTE 本身。
要安装所有依赖项,只需在插件文件夹中运行(
npm install && ./node_modules/gulp/bin/gulp.js
配置
首先,您需要加载插件。为此,编辑您的 bootstrap.php
文件并添加以下行
Plugin::load('Cirici/AdminLTE', ['bootstrap' => true]);
之后,您需要更新应用的 AppController
class AppController extends Controller { public $helpers = [ 'Gourmet/KnpMenu.Menu', 'Breadcrumbs' ]; public function initialize() { parent::initialize(); $this->loadComponent('Gourmet/KnpMenu.Menu'); } /** * @param Event $event * @return void */ public function beforeRender(Event $event) { $this->viewBuilder()->setTheme('Cirici/AdminLTE'); } }
用法
首先,查看 bootstrap.php
文件,了解您可以使用 Configure
进行哪些配置。
要加载您自定义的配置,您显然可以在需要的地方使用 Configure::write
,但推荐的方法是在您的 CONFIG
文件夹(通常为 /config
)下创建一个 adminlte.php
文件。
<?php // /config/adminlte.php return [ 'AdminLTE' => [ 'texts' => [ 'logo' => '<b>Awesome</b>Admin' ] ] ];
菜单
此插件使用 KnpMenu 来管理其菜单,并且还包括一个 Yaml 解析器,因此您只需用三行代码和一个 yaml 文件就可以轻松创建菜单
use Cake\Event\EventManager; use Cirici\AdminLTE\Renderer\YamlMenuParser; EventManager::instance()->on('AdminLTE.menu.sidebar', function ($event, $menu) { $yaml = new YamlMenuParser($menu, 'admin_menu_sidebar.yaml'); });
例如,以下是一个 yaml 文件
Settings: uri: '#' attributes: icon: gears children: Users: uri: /admin/users attributes: icon: users children: Add user: uri: /admin/users/add attributes: icon: user-plus Roles: uri: /admin/roles attributes: icon: suitcase
当前模板中只定义了
sidebar
菜单栏。
请注意,有一个特殊的属性 icon
,您可以使用它轻松显示 FontAwesome 图标。只需使用图标名称,然后 AdminLTERenderer
会完成剩余的工作。
如果您使用 PHP 设置菜单项,可以这样做
$posts = $menu->addChild('Posts', [ 'uri' => ['_name' => 'posts.admin.index'], 'icon' => 'newspaper-o' ]); $posts->addChild('Add posts', [ 'uri' => ['_name' => 'posts.admin.add'], 'icon' => 'plus' ]);
面包屑
使用 BreadcrumbsHelper::add
方法添加面包屑
<?php $this->Breadcrumbs->add('Posts', '/posts'); $this->Breadcrumbs->add($yourCurrentPost->title);
视图块
布局的许多部分可以通过定义一些视图块来管理。
因此,我们建议创建一个自定义布局,您的视图将扩展该布局。
在您想要的位置创建一个 admin.ctp
文件,在那里添加您自定义的 AdminLTE 视图块,然后让您的视图扩展该布局
<?php // src/Templates/admin.ctp $this->start('AdminLTE.user.sidebar'); echo 'Hello ' . $this->Session->read('Auth.User.username') . '!'; $this->end('AdminLTE.user.small');
然后,在您的视图中
<?php $this->extend('/admin');
以下是当前定义的所有视图块
副标题
AdminLTE.user.small
AdminLTE.user.detail
AdminLTE.user.sidebar
AdminLTE.sidebar.right
不要忘记查看官方 AdminLTE 存储库,了解如何正确定义每个部分。
许可协议
由 Òscar Casajuana 为 Cirici New Media 创建
AdminLTE theme for CakePHP 3
Copyright (C) 2016 Òscar Casajuana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://gnu.ac.cn/licenses/>.