vi-kon / laravel-utilities
此包已被废弃且不再维护。未建议替代包。
Laravel 5 通用工具
v2.2.0
2015-05-01 16:25 UTC
Requires
- php: >=5.3.0
- illuminate/support: ~5.0
- symfony/console: ^2.6
Suggests
- vi-kon/laravel-smarty-view: Smarty template engine for Laravel 5
This package is not auto-updated.
Last update: 2021-03-05 21:41:23 UTC
README
Laravel 5 通用工具。视图辅助类和其他有用类。
目录
已知问题
无
待办事项
- 修复即将到来的错误
- 完成文档
变更
版本 2.1
- 用 ConsoleProgressbar 特质替换了 Seeder 类的功能
版本 2.0
- Laravel 5 支持(要求)
- 删除了 Controller 类(Laravel 5 通过 FormRequest 类支持验证)
- 新增中间件特性(IsAjax)
- 使用 Laravel 5 的新特性和约定进行代码优化
安装
基础
将以下行添加到您的 composer.json
文件中
// to your "require" object "vi-kon/laravel-utilities": "2.*"
在您的 Laravel 5 项目中,将以下行添加到 app.php
// to your providers array 'ViKon\Utilities\UtilitiesServiceProvider',
中间件
要使用分配给路由的中间件类,需要在您的 app/Providers/RouteServiceProvider
类的 middleware
属性中分配简写键
// to your middleware array 'ajax' => 'ViKon\Utilities\Middleware\IsAjax',
视图
- html5-layout - HTML 5 布局
html5-layout
有两个模板。一个是用于 Blade 模板引擎的,另一个是用于 Smarty 模板引擎的。
注意: html5-layout.tpl 需要 vi-kon/laravel-smarty-view 包中实现的 Smarty 函数。
可用的块/部分
名称 | 描述 |
---|---|
author | 作者元数据 |
body | body 根部的空块 |
description | 描述元数据 |
head | 其他头部内容的空块 |
scripts | body 标签关闭后的脚本 |
scripts-head | 包含头部脚本的空块 |
styles | 包含样式的空块 |
title | 页面标题 |
viewport | 视口元数据 |
块/部分定义
author
<!-- ... other head stuff ... --> <meta name="author" content="@yield('author', 'Kovács Vince')"/> <!-- ... other head stuff ... -->
<!-- ... other head stuff ... --> <meta name="author" content="{block name="author"}Kovács Vince{/block}"> <!-- ... other head stuff ... -->
body
<body> @yield('body') </body>
<body> {block name="body"}{/block} </body>
description
<!-- ... other head stuff ... --> <meta name="description" content="@yield('description')"/> <!-- ... other head stuff ... -->
或
<!-- ... other head stuff ... --> <meta name="description" content="{block name="description"}{/block}"> <!-- ... other head stuff ... -->
头部
<head> <!-- ... other head stuff ... --> @yield('head') </head>
或
<head> <!-- ... other head stuff ... --> {block name="head"}{/block} </head>
脚本
<!-- ... body inner ... --> </body> @yield('scripts') </html>
或
<!-- ... body inner ... --> </body> {block name="scripts"}{/block} </html>
脚本头部
<head> <!-- ... other head stuff ... --> @yield('scripts-head') <!-- ... other head stuff ... --> </head>
或
<head> <!-- ... other head stuff ... --> {block name="scripts-head"}{/block} <!-- ... other head stuff ... --> </head>
样式
<head> <!-- ... other head stuff ... --> @yield('styles') <!-- ... other head stuff ... --> </head>
或
<head> <!-- ... other head stuff ... --> {block name="styles"}{/block} <!-- ... other head stuff ... --> </head>
标题
<!-- ... other head stuff ... --> <title>@yield('title', 'HTML 5 Layout')</title> <!-- ... other head stuff ... -->
或
<!-- ... other head stuff ... --> <title>{block name="title"}HTML 5 Layout{/block}</title> <!-- ... other head stuff ... -->
视口
<head> <!-- ... other header stuff ... --> @section('viewport') <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> @show <!-- ... other header stuff ... --> </head>
或
<head> <!-- ... other header stuff ... --> {block name="viewport"} <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> {/block} <!-- ... other header stuff ... --> </head>
用法
示例 "app-layout.tpl"
{extends file="view:utilities::html5-layout"} {block name="title"}{strip} {lang}app.title{/lang} {/strip}{/block} {block name="description"}{strip} {lang}app.description{/lang} {/strip}{/block} {block name="styles"}{strip} {html_style _url="vendor/bootstrap/css/bootstrap.min.css"} {html_style _url="vendor/bootstrap-tokenfield/bootstrap-tokenfield.min.css"} {/strip}{/block} {block name="scripts-head" append}{strip} {html_script _url="vendor/jquery/jquery-2.1.0.min.js"} {html_script _url="vendor/bootstrap/js/bootstrap.min.js"} {html_script _url="vendor/bootstrap-tokenfield/bootstrap-tokenfield.min.js"} {/strip}{/block} {block name="scripts" append}{strip} {html_script _url="js/bootstrap-setup.js"} {/strip}{/block} {block name="body"}{strip} <div class="container"> {* Page menu *} <div class="page-header"> <div class="row"> <div class="col-sm-8"> <h1>{lang}app.header.title{/lang}</h1> <p class="lead text-muted">{lang}app.header.title-lead{/lang}</p> </div> {if $user !== null} <div class="col-sm-4 text-right"> {$user['username']} | <a href="{url _name="user.ajax.modal.edit"}" type="button" rel="tooltip" data-toggle="modal" data-target="#modal"> {lang}app.header.btn.settings{/lang} </a> | <a href="{url _name="auth.logout"}">{lang}app.header.btn.logout{/lang}</a> </div> {/if} </div> </div> </div> <div class="container"> {* Block container for subpage content *} {block name="container"}{/block} </div> {/strip}{/block}
类
- 迁移 - 数据库迁移的辅助方法
特质
- ConsoleProgressbar - 控制台应用程序的进度条
ConsoleProgress特质
此特质有助于在控制台显示进度条
输出
############-------------------------------------- 24.54% (124,752/508,331)
用法
// Initialize progressbar $this->initProgressbar(); // Reset progress and output a message $this->startProgress('Seed agt_agent_types table'); // Set progressbar elements $this->setProgressMax(12); // ... // Make step in progressbar $this->progress();
中间件
实用工具中间件类允许不同的功能。
- IsAjax - 检查当前请求是否为Ajax请求
IsAjax中间件
检查当前请求是否为Ajax请求。如果不是Ajax请求,则抛出 NotFoundHttpException
异常。
用法
$options = [ 'middleware' => 'ajax', ]; Route::get('URL', $options);
辅助函数
辅助函数是应用程序函数和方法的快捷方式或别名。
json_response函数
json_response
函数是new JsonResponse
的别名。
许可证
此软件包受MIT许可证的许可。