laravel administrator 一款通用的后台插件(PHP框架扩展)

前几天我看了一下zend framework 2的一些官方文档,也找了一些例子,可惜所有的资料少之甚少。于是我就开始去找这国外用的比较流行的PHP框架laravel,希望能够找到其合适的例子,而且我本就打算写一套后台管理系统,却正好发现了其扩展的包。Laravel-Administrator后台扩展包,提供了基本上通用的界面以及数据操作的例子,我们再也不需要自己去找模板了,特别在这个html5开始盛行的时候,一步步苦苦摸索实在太费时费力。做过后台的朋友不妨看看,这可以使你的工作更快快速和方便。

1、安装composer

自从vim有统一的插件管理工具pathogen后,估摸着PHP的爱好者才想出了这么一个主意,统一的(依赖)管理器,开源插件进行统一管理也的确势在必行,不说废话了,首先看看怎么安装这个东西吧。

curl -s http://getcomposer.org/installer| php && mv composer.phar /usr/sbin/composer

2、创建你的laravel项目

一条命令就帮你搭建好了基本的架构,是不是很方便呢?

composer create-project laravel/laravel your-project-name #记得改成你的项目名称

3、安装Laravel-Administrator包

cd your-project-name && vim composer.json #进入项目目录并编辑composer.json,把"frozennode/administrator": "dev-master"加入到"require"下

以下为最终的配置:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.2.*",
        "frozennode/administrator": "dev-master"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}

4、配置包加载

vim app/config/app.php #找到数组providers,并在最后加入‘Frozennode\Administrator\AdministratorServiceProvider‘,

以下为最终的配置:

<?php

return array(

    /*
    |--------------------------------------------------------------------------
    | Application Debug Mode
    |--------------------------------------------------------------------------
    |
    | When your application is in debug mode, detailed error messages with
    | stack traces will be shown on every error that occurs within your
    | application. If disabled, a simple generic error page is shown.
    |
    */

    ‘debug‘ => true,

    /*
    |--------------------------------------------------------------------------
    | Application URL
    |--------------------------------------------------------------------------
    |
    | This URL is used by the console to properly generate URLs when using
    | the Artisan command line tool. You should set this to the root of
    | your application so that it is used when running Artisan tasks.
    |
    */

    ‘url‘ => ‘http://pfadmins.local.com‘,

    /*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */

    ‘timezone‘ => ‘UTC‘,

    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    ‘locale‘ => ‘en‘,

    /*
    |--------------------------------------------------------------------------
    | Application Fallback Locale
    |--------------------------------------------------------------------------
    |
    | The fallback locale determines the locale to use when the current one
    | is not available. You may change the value to correspond to any of
    | the language folders that are provided through your application.
    |
    */

    ‘fallback_locale‘ => ‘en‘,

    /*
    |--------------------------------------------------------------------------
    | Encryption Key
    |--------------------------------------------------------------------------
    |
    | This key is used by the Illuminate encrypter service and should be set
    | to a random, 32 character string, otherwise these encrypted strings
    | will not be safe. Please do this before deploying an application!
    |
    */

    ‘key‘ => ‘4g1RkrnrYg1UdkEHxUV3p8UBAlnTmWiZ‘,

    ‘cipher‘ => MCRYPT_RIJNDAEL_128,

    /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    ‘providers‘ => array(

        ‘Illuminate\Foundation\Providers\ArtisanServiceProvider‘,
        ‘Illuminate\Auth\AuthServiceProvider‘,
        ‘Illuminate\Cache\CacheServiceProvider‘,
        ‘Illuminate\Session\CommandsServiceProvider‘,
        ‘Illuminate\Foundation\Providers\ConsoleSupportServiceProvider‘,
        ‘Illuminate\Routing\ControllerServiceProvider‘,
        ‘Illuminate\Cookie\CookieServiceProvider‘,
        ‘Illuminate\Database\DatabaseServiceProvider‘,
        ‘Illuminate\Encryption\EncryptionServiceProvider‘,
        ‘Illuminate\Filesystem\FilesystemServiceProvider‘,
        ‘Illuminate\Hashing\HashServiceProvider‘,
        ‘Illuminate\Html\HtmlServiceProvider‘,
        ‘Illuminate\Log\LogServiceProvider‘,
        ‘Illuminate\Mail\MailServiceProvider‘,
        ‘Illuminate\Database\MigrationServiceProvider‘,
        ‘Illuminate\Pagination\PaginationServiceProvider‘,
        ‘Illuminate\Queue\QueueServiceProvider‘,
        ‘Illuminate\Redis\RedisServiceProvider‘,
        ‘Illuminate\Remote\RemoteServiceProvider‘,
        ‘Illuminate\Auth\Reminders\ReminderServiceProvider‘,
        ‘Illuminate\Database\SeedServiceProvider‘,
        ‘Illuminate\Session\SessionServiceProvider‘,
        ‘Illuminate\Translation\TranslationServiceProvider‘,
        ‘Illuminate\Validation\ValidationServiceProvider‘,
        ‘Illuminate\View\ViewServiceProvider‘,
        ‘Illuminate\Workbench\WorkbenchServiceProvider‘,
        ‘Frozennode\Administrator\AdministratorServiceProvider‘,

    ),

    /*
    |--------------------------------------------------------------------------
    | Service Provider Manifest
    |--------------------------------------------------------------------------
    |
    | The service provider manifest is used by Laravel to lazy load service
    | providers which are not needed for each request, as well to keep a
    | list of all of the services. Here, you may set its storage spot.
    |
    */

    ‘manifest‘ => storage_path().‘/meta‘,

    /*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don‘t hinder performance.
    |
    */

    ‘aliases‘ => array(

        ‘App‘             => ‘Illuminate\Support\Facades\App‘,
        ‘Artisan‘         => ‘Illuminate\Support\Facades\Artisan‘,
        ‘Auth‘            => ‘Illuminate\Support\Facades\Auth‘,
        ‘Blade‘           => ‘Illuminate\Support\Facades\Blade‘,
        ‘Cache‘           => ‘Illuminate\Support\Facades\Cache‘,
        ‘ClassLoader‘     => ‘Illuminate\Support\ClassLoader‘,
        ‘Config‘          => ‘Illuminate\Support\Facades\Config‘,
        ‘Controller‘      => ‘Illuminate\Routing\Controller‘,
        ‘Cookie‘          => ‘Illuminate\Support\Facades\Cookie‘,
        ‘Crypt‘           => ‘Illuminate\Support\Facades\Crypt‘,
        ‘DB‘              => ‘Illuminate\Support\Facades\DB‘,
        ‘Eloquent‘        => ‘Illuminate\Database\Eloquent\Model‘,
        ‘Event‘           => ‘Illuminate\Support\Facades\Event‘,
        ‘File‘            => ‘Illuminate\Support\Facades\File‘,
        ‘Form‘            => ‘Illuminate\Support\Facades\Form‘,
        ‘Hash‘            => ‘Illuminate\Support\Facades\Hash‘,
        ‘HTML‘            => ‘Illuminate\Support\Facades\HTML‘,
        ‘Input‘           => ‘Illuminate\Support\Facades\Input‘,
        ‘Lang‘            => ‘Illuminate\Support\Facades\Lang‘,
        ‘Log‘             => ‘Illuminate\Support\Facades\Log‘,
        ‘Mail‘            => ‘Illuminate\Support\Facades\Mail‘,
        ‘Paginator‘       => ‘Illuminate\Support\Facades\Paginator‘,
        ‘Password‘        => ‘Illuminate\Support\Facades\Password‘,
        ‘Queue‘           => ‘Illuminate\Support\Facades\Queue‘,
        ‘Redirect‘        => ‘Illuminate\Support\Facades\Redirect‘,
        ‘Redis‘           => ‘Illuminate\Support\Facades\Redis‘,
        ‘Request‘         => ‘Illuminate\Support\Facades\Request‘,
        ‘Response‘        => ‘Illuminate\Support\Facades\Response‘,
        ‘Route‘           => ‘Illuminate\Support\Facades\Route‘,
        ‘Schema‘          => ‘Illuminate\Support\Facades\Schema‘,
        ‘Seeder‘          => ‘Illuminate\Database\Seeder‘,
        ‘Session‘         => ‘Illuminate\Support\Facades\Session‘,
        ‘SoftDeletingTrait‘ => ‘Illuminate\Database\Eloquent\SoftDeletingTrait‘,
        ‘SSH‘             => ‘Illuminate\Support\Facades\SSH‘,
        ‘Str‘             => ‘Illuminate\Support\Str‘,
        ‘URL‘             => ‘Illuminate\Support\Facades\URL‘,
        ‘Validator‘       => ‘Illuminate\Support\Facades\Validator‘,
        ‘View‘            => ‘Illuminate\Support\Facades\View‘,

    ),

);

5、生成Laravel-Administrator配置

  php artisan config:publish frozennode/administrator #生成配置
  vim app/config/packages/frozennode/administrator/administrator.php #你可以编辑此文件配置后台参数

6、配置Laravel-Administrator例子

如果没有示例我们也不知道如何开始,那么就让我们看看这个插件包所给出的例子吧。

  cd ../ #退到工作目录
  git clone https://github.com/FrozenNode/Laravel-Administrator #下载插件
  cp Laravel-Administrator/examples/app/config/packages/frozennode/administrator/administrator.php your-project-name/app/config/packages/frozennode/administrator/
  cp Laravel-Administrator/examples/app/config/administrator your-project-name/app/config/ -r
  cp Laravel-Administrator/examples/app/models your-project-name/app/ -r
  cp Laravel-Administrator/examples/app/database/migrations/* your-project-name/app/database/migrations/
  mkdir -p your-project-name/public/packages/frozennode/administrator
  cp Laravel-Administrator/public/* your-project-name/public/packages/frozennode/administrator/ -r
  #创建数据库
  #首先根据你数据库的配置创建出你需要的数据,这里以mysql为例
  cd your-project-name # 进入你的项目目录
  vim app/config/database.php

以下为我的配置:

<?php

return array(

    /*
    |--------------------------------------------------------------------------
    | PDO Fetch Style
    |--------------------------------------------------------------------------
    |
    | By default, database results will be returned as instances of the PHP
    | stdClass object; however, you may desire to retrieve records in an
    | array format for simplicity. Here you can tweak the fetch style.
    |
    */

    ‘fetch‘ => PDO::FETCH_CLASS,

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    ‘default‘ => ‘mysql‘,

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    ‘connections‘ => array(

        ‘sqlite‘ => array(
            ‘driver‘   => ‘sqlite‘,
            ‘database‘ => __DIR__.‘/../database/production.sqlite‘,
            ‘prefix‘   => ‘‘,
        ),

        ‘mysql‘ => array(
            ‘driver‘    => ‘mysql‘,
            ‘host‘      => ‘localhost‘,
            ‘database‘  => ‘pf_admindb‘,
            ‘username‘  => ‘root‘,
            ‘password‘  => ‘mysql‘,
            ‘charset‘   => ‘utf8‘,
            ‘collation‘ => ‘utf8_unicode_ci‘,
            ‘prefix‘    => ‘‘,
        ),

        ‘pgsql‘ => array(
            ‘driver‘   => ‘pgsql‘,
            ‘host‘     => ‘localhost‘,
            ‘database‘ => ‘forge‘,
            ‘username‘ => ‘forge‘,
            ‘password‘ => ‘‘,
            ‘charset‘  => ‘utf8‘,
            ‘prefix‘   => ‘‘,
            ‘schema‘   => ‘public‘,
        ),

        ‘sqlsrv‘ => array(
            ‘driver‘   => ‘sqlsrv‘,
            ‘host‘     => ‘localhost‘,
            ‘database‘ => ‘database‘,
            ‘username‘ => ‘root‘,
            ‘password‘ => ‘‘,
            ‘prefix‘   => ‘‘,
        ),

    ),

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven‘t actually been run in the database.
    |
    */

    ‘migrations‘ => ‘migrations‘,

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    ‘redis‘ => array(

        ‘cluster‘ => false,

        ‘default‘ => array(
            ‘host‘     => ‘127.0.0.1‘,
            ‘port‘     => 6379,
            ‘database‘ => 0,
        ),

    ),

);

保证数据库用户、密码、IP、端口正确的情况下,还需保证你的数据库存在后再执行以下命令。

  php artisan migrate:install && php artisan migrate # 创建数据库及表
  #以下是创建生成数据库表的一些命令,了解即可
  #php artisan migrate:make create_directors_table
  #php artisan migrate:make create_films_table
  #php artisan migrate:make create_box_office
  #php artisan migrate:make create_actors
  #php artisan migrate:make create_actors_films
  #php artisan migrate:make create_theaters
  #php artisan migrate:make create_films_theaters

7、配置你的网站

上次说到配置zend framework 2的时候,特别讲到这个配置,而laravel配置是一模一样的。

  server {
    listen 80;
    server_name zf2.local.com; #域名
    root /data/www/zf2/public; #你的网站目录,即项目目录记得加上public,否则访问方法不同
    index index.php;
    #charset utf-8;
    location ~* \.(js|ico|gif|jpg|png|css|jpeg|swf)$ {
      access_log off;
      expires 2d;
    }

    location / {
      if (!-f $request_filename) {
        rewrite ^(.+)$ /index.php?$1& last;
      }
    }

    location ~ \.php$ {
      #root /var/www/html/public;
      fastcgi_pass 127.0.0.1:9000; #如果你的php-fpm的监听端口不是这个,请设置
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache’s document root
    # concurs with nginx’s one
    #
    location ~ /\.ht {
      deny all;
    }
  }

8、开始浏览你的网站

将服务器IP与你的域名绑定,开始浏览,我这里的地址为http://pfadmins.local.com/admin。一定要加上admin,因为后台的url就在admin,当然你可以配置。

时间: 2024-08-30 07:48:12

laravel administrator 一款通用的后台插件(PHP框架扩展)的相关文章

一款德国的Nagios插件---Check_mk 搭建

经过两周的研究与测试,把Check_Mk摸得40%程度,在这里简单的总结一下并分享给大家,可能还存在问题,请大家多多指点.. Check_mk 安装 第 1 章  check_mk的介绍 Check_MK是一款通用的Nagios/Icinga数据采集插件,主要由三个子项目组成.它采用了新的方法从操作系统和网络组件中收集数据和淘汰老式的NRPE.check_by_ssh.NSClient和check_snmp.其优点能够自动检测主机上的监控项目,并且在监控端的CPU使用率也显著减少.其遵循CPL

easyweb通用管理后台系列——介绍

欢迎关注微信公众号[千里授渔].或者添加QQ507545336 介绍: easyweb使用spring boot技术构建的一套通用管理后台,目前处于开发阶段;不断完善开发中github项目地址https://github.com/egojit8/easyweb,在开发之初就考虑分布式,后期利用spring cloud技术快速改造成分布式,实现负载均衡熔断等功能: easyweb使用技术: 技术 名称 官网 Spring boot 创建独立的Spring应用程序 http://projects.s

Vue Element+Node.js开发企业通用管理后台系统

第1章 课程介绍介绍项目背景.达到的目标.技术栈和功能演示 第2章 课程分析课程分析 第3章 Vue进阶(上)对Vue的进阶知识进行讲解,包括$emit和$on.directive指令.组件化.Vue插件等相关内容. 第4章 Vue进阶(下)对Vue的进阶知识进行讲解,包括组件通信.过滤器.监听器.Vue2.6重要新特性等相关内容. 第5章 Element-UI入门对Element-UI的内容进行讲解,包括如何搭建Element-UI使用环境,如何使用插件快速集成Element-UI,并通过el

开源一款私藏Management Studio插件,ProjkyAddin,送给所有使用SQLServer的园友们

ProjkyAddin 是一款Management Studio 插件,安装包才500多kb,兼容SSMS 2005.SSMS 2008.SSMS 2008 R2.SSMS 2012.SSMS 2014,功能是为硬盘上的脚本文件在Management Studio工具栏中提供一个快捷方式,直接点击快捷方式的按钮就能在当前查询窗口(若没有,则新建一个查询窗口)添加脚本内容.开放源码,可以根据需要自己定制加载脚本内容的部分.类似于IE浏览器的收藏夹栏功能. 有了这个插件,就能将常用的脚本直接在Man

10 款优秀的文件管理插件推荐

本文整理了10款优秀的文件管理插件,这些插件基于jQuery.AJAX和PHP,你可以轻松进行定制并加入到自己的项目中.通过它们,你和用户可以通过浏览器来预览.上传.修改文件和文件夹. 1. elFinder 基于web的简单文件管理器. 源码 + 演示 2. jQuery File Tree 一个基于jQuery的.可配置的AJAX文件浏览插件.你最少只需一行JavaScript代码,即可创建一个自定义的.完全交互式的文件树. 源码 / 演示 3. jquery-filemanager 轻松管

Web开发者必备的20款超赞jQuery插件(转载)

jQuery的易扩展性吸引了来自全球的开发者来共同编写jQuery插件.jQuery插件不仅能够增强网站的可用性,有效地改善用户体验,还可以大大减少开发时间.现在的jQuery插件很多,可以根据您的项目需要来选择.这里为您介绍20款非常不错的插件. Creative Radical Web Typography Lettering.js是一个轻量经的.易于使用的jQuery插件,可创造出极具个性的网页排版,是2010年最佳jQuery插件之一. 演示 | 下载 New FancyMoves Jq

Vue Element+Node.js开发企业通用管理后台系统完整教程

资源获取链接:点击获取完整教程 Vue Element+Node.js开发企业通用管理后台系统 综合应用 Vue 和 Node 技术,基于 Element-UI 组件库搭建“小慕读书“的管理后台,通过 Node 实现了电子书上传和解析功能以及权限管理.课程对 Vue 和 Node 有较为深入的应用,不仅会教大家如何实现功能,更会讲解技术背后的原理,帮助大家做到举一反三.课程面向中高级开发者,提供完整的开发文档和API支持,让大家可以快速上手实战 准备阶段 准备工作 Nginx 服务器MySQL

(C/C++)基于SharpUI控件库的插件式框架开发--第一篇简介

看到题目,很明显这里要说的是插件式框架的开发,当然是用c/c++来实现的.开发对于我来说,是一种爱好,但并非科班出身,所以这里要说的一点分享就是,开发并不是会写代码就行了,最主要的是要有思路想法,比如要实现一个功能,就要知道,这个功能到底是要来实现啥的,要实现它需要什么样的算法等等,做到胸中有丘壑,再去用最简单代码去实现它,就会发现写代码是一件很享受的事情. 参加工作快两年了,一开始的是用C#开发,写了半年多的功能和小控件,上手之后,参考ICSharpCode.Core.Presentation

插件式框架平台

二.插件式框架平台 以插件编程为指导思想,动态反射调用组件为行动方针,深入调研.设计.编码,初步形成现代化软件架构. 简介 有了理论指导,就需要用实践去验证.所谓知行合一. 作为一款通用插件式开发框架,基础的插件内核是整个平台的核心.鉴于平台的通用性和易用性,还插件式的提供以下常用基础模块功能: 1. 工作流组件 2. 权限系统组件 3. 自动更新组件 4. 自定义UI套件 5. 轻量级ORM 6. 字典管理 7. 通用类库 2.1 插件内核 本平台的插件内核开发借鉴了SD中服务和插件树思想,以