前几天我看了一下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,当然你可以配置。

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

  1. 程序猿必备的10款web前端开发插件一

    1.CSS3实现的火柴燃烧Loading加载动画 这次我们要给大家分享一款非常特别的CSS3 Loading加载动画,整个Loading加载动画就好像是火柴在燃烧一样,不足的是火苗并没有那么真实,比较 ...

  2. 24款WordPress网站AI插件大盘点

    ------------恢复内容开始------------ 你想把AI(人工智能)技术和机器学习技术添加到自己的WordPress网站吗?本文中,我会分享24个利用AI技术和机器学习技术的WordP ...

  3. 【转】2014年25款最好的jQuery插件

    2014年25款最好的jQuery插件 来源:Specs' Blog-就爱PHP   时间:2014-12-30 10:24:10   阅读数:2267 分享到: 0 http://www.php10 ...

  4. 10款jQuery文本高亮插件

    [编者按]本文作者为 Julian Motz,主要介绍十款 jQuery 文本高亮插件的现状.文章系国内 ITOM 管理平台 OneAPM 编译呈现. 很多应用或网站都为用户提供搜索关键词的方法.为了 ...

  5. django admin后台插件:django-suit入门

    去年9月底开始用django来做公司内部项目,开始对django有了一些了解,感觉django真的蛮强大的(也有很多人推荐flask,将来有空的话我会试试).今天的话只是介绍一个小东西,django管 ...

  6. 推荐几款常用的Eclipse插件

    Eclipse 应该说是老牌也是最常用的Java开发工具,尽管这几年 InstelliJ IDEA 的发展势头很强劲,身边使用和推崇的人也大有人在,但个人而言还是觉有些不太习惯.这里也介绍几款自己常用 ...

  7. FineAdmin.Mvc 使用ok-admin+ASP.NET MVC搭建的通用权限后台管理系统

    FineAdmin.Mvc 介绍 使用ok-admin+ASP.NET MVC搭建的通用权限后台管理系统RightControl后台layui模板不太好看,换成ok-admin v2.0重写一遍.项目 ...

  8. Idea没安装几款好用的插件,怎么风骚的写代码???

    ​ 工欲善其事,必先利其器,好的工具可以提升我们的开发效率,越来越多的Java程序员从Eclipse转到了Jetbrains家的Idea.今天给大家介绍的是我常用的十几款Idea必装的插件. ​ Ti ...

  9. 几款开源的hybird移动app框架分析

    几款开源的Hybrid移动app框架分析 Ionic Onsen UI 与 ionic 相比 jQuery Mobile Mobile Angular UI 结论 很多移动开发者喜欢使用原生代码开发, ...

随机推荐

  1. 携带cookie进行数据请求

    前端进行数据请求有:普通的ajax(json)请求,jsop跨域请求,cors跨域请求,fetch请求...PC端这些请求方式中,普通的ajax(json)请求和jsop跨域请求是默认携带cookie ...

  2. MySql基本概念(一)

    MySQL基本概念 一. 数据库系统概述: mysql是数据库系统的一种,下面是所有数据库系统中主要的组件. 数据库系统由硬件部分和软件部分构成,硬件主要用于存储数据库中的数据,包括计算机.存储设备. ...

  3. AFNetworking 3.0 源码解读 总结

    终于写完了 AFNetworking 的源码解读.这一过程耗时数天.当我回过头又重头到尾的读了一篇,又有所收获.不禁让我想起了当初上学时的种种情景.我们应该对知识进行反复的记忆和理解.下边是我总结的 ...

  4. DB2导入导出数据库数据

    导出数据库中数据 在db2cmd命令下生成建库脚本(-z指定模式名) db2look -d BBS -z db2admin -u db2admin -e -o bbs.sql 在db2cmd命令下导出 ...

  5. uniqid函数产生唯一id,减少碰撞几率

    $uuid = str_replace(".","",uniqid(mt_rand(100000,999999),true)); //基于当前时间微妙数,与mt ...

  6. Win8&Win2012R2如何支持DOTA2输入法

    微软自带的拼音和五笔就不用看了,没研究过,下面的方法应该不支持. 其实方法很简单运行下ctfmon.exe就可以了,这个原来旧输入模式的基础,测试可以支持QQ五笔. PS:使用拼音输入法的用户可以直接 ...

  7. 原 ng-include用法分析以及多标签页面的简单实现方式

    Demo:http://webenh.chinacloudsites.cn/Default/Demo2 在平时的项目开发中,应该会经常遇到上图所示的需求,就是在一个页面中有多个标签,被选中的标签颜色会 ...

  8. asp.net mvc 应用Bundle(捆绑和微小)压缩技术 启用 BundleConfig 配置web.config

    从MVC4开始,我们就发现,项目中对Global.asax进行了优化,将原来在MVC3中使用的代码移到了 [App_Start]文件夹下,而Global.asax只负责初始化.其中的BundleCon ...

  9. 【转】探索C#之布隆过滤器(Bloom filter)

    原文:蘑菇先生,http://www.cnblogs.com/mushroom/p/4556801.html 背景介绍 Bloom filter(后面简称BF)是Bloom在1970年提出的二进制向量 ...

  10. 发现一个国内牛逼的maven仓库,速度真的太快了

    前天网上下了一个项目,在公司还好,网络比较流畅,很快就把依赖下好了:回家的时候,想耍耍,结果下了一天也没把依赖下好,速度是几k每秒,甚至一k每秒,哎~心都碎了,网上一搜,结果发现了一个惊天的用nexu ...