Luthier-CI-中间件-Middleware

中间件 Middleware内容 Contents介绍 Introduction中间值执行点 Middleware execution points创建中间件 Create a middleware分配中间值 Assign a middleware 全局中间件 Global Middleware路由中间件 Route middleware运行中间件 Run a middleware 中间件参数 Middleware parameters外部中间件 External middleware 介绍 ( Introduction )将中间件视为一组层,请求必须在您的应用程序中通过才能到达资源。 例如,使用中间件,您可以验证用户是否已登录并具有足够的权限来访问应用程序的某些部分,否则将其重定向到其他位置。 实际上,中间件是控制器的扩展,因为框架的单例已经在此时构建,您可以使用该ci()函数来获取它。 中间件执行点 ( Middleware execution points )有两个执行点: pre_controller: 此时定义的中间件将在控制器构造函数之后执行,但在执行任何控制器操作之前执行。post_controller: 此时定义的中间件将完全在post_controllerCodeIgniter 的本机钩子上运行。控制器构造函数始终首先执行 这是CodeIgniter的行为,而Luthier CI不会对其进行修改。 在某些时候您可能需要在中间件之前执行代码,这样做的方法是在控制器中定义一个名为的公共方法preMiddleware: <?php# application/controllers/TestController.phpdefined('BASEPATH') OR exit('No direct script access allowed');class TestController extends CI_Controller{ public function preMiddleware() { // This will be executed after the constructor (if it exists), but before the middleware }}作为路由在回调中不可用 ...

May 6, 2019 · 2 min · jiezi

Luthier-CI-例子-Examples

例子 Examples例子 # 1: 多语言网站 Multi-language website这是一个示例,显示了由URL管理的多语言网站。中间件用于加载当前语言文件。 <?php# application/routes/web.phpRoute::get('/', function(){ // Route "by default". This is a good place to request a cookie, session variable    // or something that allows us to restore the last language of the user, or show a    // language selection screen if no information is provided. redirect(route('homepage', ['_locale' => 'en']));});Route::group('{((es|en|it|br|ge)):_locale}', ['middleware' => ['Lang_middleware']], function(){ Route::get('home', function(){ var_dump( ci()->lang->line('test') ); })->name('homepage'); Route::get('about', function(){ var_dump( ci()->lang->line('test') ); })->name('about');});<?php# application/middleware/Lang_middleware.phpclass Lang_middleware{ public function run() { // Obtaining the value of the "_locale" sticky parameter $locale = ci()->route->param('_locale'); $langs = [ 'es' => 'spanish', 'en' => 'english', 'it' => 'italian', 'br' => 'portuguese-brazilian', 'ge' => 'german', ]; ci()->lang->load('test', $langs[$locale]); }}

May 6, 2019 · 1 min · jiezi

Luthier-CI-命令行-Command-line

命令行 Command line内容 Contents介绍 Introduction句法 Syntax使用CLI路由 Using CLI routes内置CLI工具 Built-in CLI tools 激活 Activation'luthier make'命令 'luthier make' command'luthier migrate'命令 'luthier migrate' command 介绍 ( Introduction )感谢Luthier CI,您可以通过命令行界面(CLI)利用框架提供的各种可能性。 句法 SyntaxCLI路由的语法类似于HTTP和AJAX路由。必须在application/routes/cli.php文件中定义CLI路由 例: <?php# application/routes/cli.php// Using anonymous functionsRoute::cli('test', function(){ // <- (note that here the method is 'cli' and not 'get', 'post', etc.) echo 'Hello world!';});// Pointing to an existing controllerRoute::cli('test2', 'foo@bar');CLI路由共享与HTTP / AJAX对应的相同属性,您可以在此处了解有关它们的更多信息。 使用CLI路由 Using CLI routesCLI路由共享与HTTP / AJAX对应的相同属性,您可以在此处了解有关它们的更多信息。 ...

May 6, 2019 · 2 min · jiezi

Luthier-CI-简单的认证-SimpleAuth

简单的认证 SimpleAuth内容 Contents介绍 Introduction安装 Installation 第1步:复制所需的文件 Step 1: Copy the required files第2步:安装数据库 Step 2: Install the database第3步:定义路线 Step 3: Define the routesSimpleAuth控制器 SimpleAuth Controller 自定义用户注册表单 Customize the user registration formSimpleAuth中间件 SimpleAuth MiddlewareSimpleAuth库 SimpleAuth Library 基本功能 Basic functions 获取当前用户 Obtaining the current user验证用户是否是来宾(匿名) Verify if a user is a guest (anonymous)验证用户的角色 Verify the role of a user验证用户的权限 Verify the user's permissions访问控制列表(ACL)功能 Access Control List (ACL) functions其他功能 Other functions意见和翻译 Views and translations ...

May 6, 2019 · 5 min · jiezi

Luthier-CI-认证-Authentication

认证 Authentication介绍 IntroductionCodeIgniter包含构建用户身份验证系统所需的所有工具。不幸的是,它缺乏易于实现,维护和扩展的集成接口或库。 Luthier CI使用受Symfony启发的身份验证模型解决了这个问题,该模型寻求尽可能多的灵活性,以便开发人员可以快速开始工作,而无需重新发明轮子。 激活 Activation作为可选模块,必须首先激活Luthier CI认证功能。为此,请转到该 application/config/hooks.php 文件并替换它: <?php# application/config/hooks.phpdefined('BASEPATH') OR exit('No direct script access allowed');// (...)$hook = Luthier\Hook::getHooks();附: <?php# application/config/hooks.phpdefined('BASEPATH') OR exit('No direct script access allowed');// (...)$hook = Luthier\Hook::getHooks( [ 'modules' => ['auth'] ]);验证工具可用 Authentication tools availableLuthier CI的身份验证有两种:SimpleAuth 和 Luthier CI Authentication Framework. SimpleAuth: 最快最有趣的方式 ( the fastest and funniest way )如果您需要的是预先配置,可自定义且易于使用的身份验证系统,SimpleAuth非常适合您。它专为最常见的身份验证设计:通过表单和数据库进行传统登录。 它的一些功能: 登录屏幕和用户注册注册时验证电子邮件重设密码用户角色“提醒我”基于cookie的功能(可选)访问控制列表(ACL)(可选)它适用于所有CodeIgniter数据库驱动程序在登录期间防止暴力攻击(可选)路线的自动定义(使用方法Route::auth())多个模板可供选择,翻译成多种语言Luthier CI Authentication Framework: 适用于高级用户 ( for advanced users )Luthier CI Authentication Framework 是一组抽象地定义用户认证处理的类和接口。有了它,您可以执行以下任务: ...

May 6, 2019 · 1 min · jiezi

Luthier-CI-调试-Debug

调试 Debug实验功能 我们已经努力使事情正常工作,但是可能会出现错误,导致和/或收取此功能所需的资产。如果您在使用过程中发生过事故,请通知我们。 内容 Contents介绍 Introduction激活 Activation调试消息 Debug messages添加您自己的数据收集器 Add your own data collectors 介绍 Introduction由于将Luthier CI与这个出色的工具集成在一起,您可以将PHP Debug Bar 添加到您的应用程序中。 激活 Activation要激活此功能(默认情况下已禁用),请转到您的 application/config/hooks.php 文件并替换: <?php# application/config/hooks.phpdefined('BASEPATH') OR exit('No direct script access allowed');// (...)$hook = Luthier\Hook::getHooks();附: <?php# application/config/hooks.phpdefined('BASEPATH') OR exit('No direct script access allowed');// (...)$hook = Luthier\Hook::getHooks( [ 'modules' => ['debug'] ]);您应该在窗口底部看到调试栏: 调试消息 Debug messages要添加调试消息,请使用该类的 log() 静态方法 Luthier\Debug: # use Luthier\Debug;Debug::log($variable, $type, $dataCollector);$variable 要调试的变量在哪里,并且 $type 是消息的类型,可以是 'info', 'warning' 或 'error'. ...

May 6, 2019 · 1 min · jiezi

Luthier-CI安装-Installation

安装 ( Installation )内容 ( Contents )要求 Requirements安装 Installation 获得Luthier CI Get Luthier CI启用Composer自动加载和挂钩 Enable Composer autoload and hooks将Luthier CI与您的应用程序连接 Connect Luthier CI with your application初始化 Initialization 要求 ( Requirements )PHP >= 5.6 (Compatible con PHP 7)CodeIgniter 3 安装 ( Installation ) 获得Luthier CI ( Get Luthier CI )需要Composer Luthier CI通过Composer安装。你可以在这里得到它。 here. 转到该application文件夹并执行以下命令: composer require luthier/luthier 启用Composer autoload 和 hooks要使Luthier CI工作,必须在框架中启用Composer 自动加载和挂钩。在文件中config.php修改以下内容: <?php# application/config/config.php// (...)$config['enable_hooks'] = TRUE;$config['composer_autoload'] = TRUE;// (...) 将Luthier CI与您的应用程序连接在hooks.php文件中,将Luthier CI挂钩分配给$hook变量: ...

May 6, 2019 · 1 min · jiezi

Luthier-CI-认证框架-Authentication-Framework

Luthier CI 认证框架 ( Authentication Framework )内容 Contents介绍 Introduction创建用户提供商 Creation of User Providers 用户实例 User instance用户加载 Users load密码哈希及其验证 Password hash and its verification验证用户是否处于活动状态并已验证 Validate that a user is active and verified与用户提供商合作 Working with User Providers 用户登录 User login高级用户登录 Advanced user login会话 Sessions 在会话中存储用户 Storing a user in the session从会话中检索用户 Retrieving a user from the session自定义会话数据 Custom session data删除当前会话 Deleting the current session用户操作 User Operations 角色验证 Roles verification权限验证 Permissions verification基于控制器的认证 Controller-based authentication ...

May 6, 2019 · 8 min · jiezi

Luthier-CI-路由-Routes

路由 ( Routes )内容 ( Contents )介绍 Introduction路由类型 Route types句法 Syntax 命名空间 Namespaces前缀 Prefixes命名路线 Named routes回调为路线 Callbacks as routes组 Groups资源路线 Resource routes默认控制器 Default controller参数 Parameters 可选参数 Optional parameters参数正则表达式 Parameter regex“粘性”参数 "Sticky" parameters 介绍 ( Introduction )Luthier CI更改CodeIgniter路由的行为: 在CodeIgniter中,默认情况下,可以在任何HTTP谓词下访问路由。使用Luthier CI时,必须为每个路由定义接受的HTTP谓词,并且任何与这些参数不匹配的请求都将生成404错误。在CodeIgniter中,可以直接从URL访问控制器,而无需定义路由。另一方面,使用Luthier CI,尝试访问未定义的路径(即使URL与控制器的名称和方法匹配)也会生成404错误。在CodeIgniter中,路由参数是指向控制器的简单正则表达式,在Luthier CI中,路由是一个独立且唯一的实体,它包含定义明确的参数以及从中构建URL的能力。在CodeIgniter中,您只能创建指向控制器的路由。使用Luthier CI,可以使用匿名函数作为控制器,甚至可以在不使用单个控制器的情况下构建完整的Web应用程序。 路由类型 ( Route types )您可以使用三种类型的路由: HTTP routes: 它们在HTTP请求下访问,并在application/routes/web.php文件中定义AJAX routes: 它们仅在AJAX请求下访问,并在application/routes/api.php文件中定义CLI routes: 它们仅在CLI(命令行界面)环境下访问,并在application/routes/cli.php文件中定义AJAX路由进入api.php 虽然你可以在 web.php 文件中定义AJAX路由,但最好这样做 api.php 如果您使用相同的URL和相同的HTTP动词定义两条或更多路线,则第一条路线将被返回ALWAYSLuthier CI允许您使用动词GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS和TRACE定义HTTP路由: 句法 ( Syntax )如果您使用过Laravel,那么您将知道如何使用Luthier CI,因为它的语法是相同的。这是路线最简单的例子: ...

May 6, 2019 · 3 min · jiezi

关于Luthier CI

欢迎关于Luthier CILuthier CI是CodeIgniter的一个插件,增加了有趣的功能,旨在简化大型网站和API的构建。它是为了尽可能地与框架集成,因此在安装Luthier CI后,应用程序中已存在的所有内容应该继续正常工作。本文档假定您具有有关CodeIgniter的基本知识。如果您从未使用过CodeIgniter,那么他们的官方文档就是一个很好的起点Luthier CI是免费软件,可在MIT许可下使用。特征改进了路由 ( Improved routing )Luthier CI通过受Laravel启发的语法取代了在应用程序中定义路由的方式。例如,而不是定义类似于此的大量路由:$route[‘catalog/cars/(:any)’][‘GET’] = ‘CarsController/catalog/$1’;$route[‘catalog/cars/(:any)/(:any)’][‘GET’] = ‘CarsController/catalog/$1/$2’;$route[‘catalog/bikes/(:any)’][‘GET’] = ‘BikesController/catalog/$1’;$route[‘catalog/bikes/(:any)’][‘POST’] = ‘BikesController/catalog/$1’;$route[‘catalog/bikes/(:any)/(:any)’][‘GET’] = ‘BikesController/catalog/$1/$2’;$route[‘catalog/bikes/(:any)/(:any)’][‘POST’] = ‘BikesController/catalog/$1/$2’;$route[‘catalog/airplanes/(:any)’][‘GET’] = ‘AirplanesController/catalog/$1/$2’;$route[‘catalog/airplanes/(:any)/(:any)’][‘GET’] = ‘AirplanesController/catalog/$1/$2’;…你可以用更紧凑的方式编写它:Route::group(‘catalog’, function(){ Route::get(‘cars/{category_id}/{filter_by?}’, ‘CarsController@catalog’); Route::match([‘get’,‘post’], ‘bikes/{category_id}/{filter_by?}’, ‘BikesController@catalog’); Route::get(‘airplanes/{category_id}/{filter_by?}’, ‘AirplanesController@catalog’);});此外,Luthier CI可以帮助您保持路由的有序性,因为每种类型的路由都有自己的文件,必须定义它:HTTP路由有一个文件,AJAX路由有另一个文件,CLI路由有另一个文件。中间件 ( Middleware )Luthier CI 在框架中引入了中间件的概念。正确使用,中间件可以帮助您在控制器上创建过滤器和操作,否则,使用库和帮助程序实现将非常繁琐。您可以在特定路由和路由组中使用中间件,甚至可以在应用程序中全局使用。简易安装Luthier CI通过Composer安装,并使用CodeIgniter 挂钩集成到您的应用程序中。忘记复制或移动文件或遵循大量的步骤以使Luthier CI工作。在大多数情况下,安装不会超过5分钟!社区和支持要报告错误并提出更改,请访问Github上的Luthier CI repository on Github存储库

March 4, 2019 · 1 min · jiezi