ciricihq/adminlte

CakePHP 的 AdminLTE 主题

安装数量: 1,688

依赖项: 0

建议者: 0

安全性: 0

星标: 9

关注者: 5

分支: 6

开放性问题: 0

类型:cakephp-plugin

0.0.2 2016-06-02 21:40 UTC

This package is auto-updated.

Last update: 2024-09-17 16:34:22 UTC


README

Build status Code coverage License Latest stable version Total downloads Code climate

安装

您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。

安装 composer 包的推荐方法是

composer require ciricihq/adminlte

安装依赖项

目前此主题使用 NPM 安装外部依赖项,如 bootstrap、fontawesome 或 AdminLTE 本身。

要安装所有依赖项,只需在插件文件夹中运行(在插件文件夹内)

npm install && ./node_modules/gulp/bin/gulp.js

配置

首先,您需要加载插件。为此,编辑您的 bootstrap.php 文件并添加以下行

Plugin::load('Cirici/AdminLTE', ['bootstrap' => true]);

之后,您可以通过让控制器扩展 AdminLTE 的 AppController,轻松地使用 AdminLTE 模板。

use Cirici\AdminLTE\Controller\AppController as BaseController;

class MyController extends BaseController
{

}

使用方法

首先,查看 bootstrap.php 文件,看看您可以使用 Configure 配置什么。

要加载您的自定义配置,您当然可以在需要的地方使用 Configure::write,但推荐的方法是在您的 CONFIG 文件夹(通常是 /config)下创建一个 adminlte.php 文件。

<?php
// /config/adminlte.php
return [
    'AdminLTE' => [
        'texts' => [
            'logo' => '<b>Awesome</b>Admin'
        ]
    ]
];

登录模板

还包括一个登录模板和布局。要使用它们,只需从您的 login 方法渲染登录模板即可。

// some kind of users Controller
public function logic()
{
    // [...]
    // Your login logic

    $this->render('Cirici/AdminLTE./Admin/Users/login');
}

菜单

此插件使用 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/>.