codeigniter的HTTP方法的定制路线2.1.4支持? [英] codeigniter 2.1.4 support for http methods custom routings?

查看:168
本文介绍了codeigniter的HTTP方法的定制路线2.1.4支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,codeigniter支持自定义路由到其他类/方法
例如

  $路线['产品/(:任何)'] =目录/ product_lookup

不过它基于HTTP请求调用网址像laravel类型支持路线?

例如。使用get方法重新路由像Laravel

 读PUT /用户/ X
路线::后(用户/ {ID}','UsersController @更新');


解决方案

官方,量产版则没有。不是对单个字文档。但是......

此功能在开发分支实施。这是从这个拉申请。下面是文档的开发版本指的是功能的一部分:


  

在路线中使用HTTP动词


  
  

如果您preFER您可以使用HTTP动词(或方法)来定义你的路由规则。构建RESTful应用程序时,这是非常有用的。您可以使用标准的HTTP动词(GET,PUT,POST,DELETE)或自定义HTTP动词(例如:清除)。 HTTP动词的规则是不区分大小写。所有你需要做的是使用HTTP动词规则添加数组索引。例如:

  $路线['产品'] ['放'] ='产品/插入';

在上面的例子中,一个PUT请求URI产品会叫的产品的控制器类和插入的方法。

  $路线['产品/(:NUM)'] ['删除'] ='产品/删除/ $ 1';


  
  

以产品为第一部分和第二一批到URL删除请求将被重新映射到产品级和删除的方法传球在比赛中作为一个变量的方法。

  $路线['产品/([A-Z] +)/(\\ d +)'] ['获得'] ='产品/ $ 1 / $ 2';

一个GET请求的URI类似产品/衬衫/ 123称之为产品的控制器类和衬衫方法,作为方法的参数个数。


  
  

使用HTTP动词是可选的,所以如果你想要的任何HTTP动词在一个规则来处理你可以只写不HTTP动词你的路由规则。例如:

  $路线['产品'] =产品;


  
  

这样一来,使用含在第一部分的产品一词的任何HTTP方法的所有传入的请求将被重新映射到产品类。


快速的解决方案是更新系统/核心/ Router.php 与特定的修改提交:的https://github.com/EllisLab/$c$cIgniter/commit/af709d6ebe6ca75913d7a9eedb4fdcd76be45c50.

另外,拉入请求引用鸽子库处理先进的路由配置。

I know that codeigniter supports custom routing to another class / method e.g.

$route['product/(:any)'] = "catalog/product_lookup";

However does it support routings based on the type of http request calling the url like in laravel ?

e.g. using get method reroute like in Laravel

Read PUT /users/X  
Route::post('users/{id}','UsersController@update');

解决方案

The official, production version does not. Not a single word on that in docs. But...

This feature is implemented in the development branch. It was merged from this pull request. Here's a part of the development version of documentation refering to that feature:

Using HTTP Verb in Routes

If you prefer you can use HTTP Verb (or method) to define your routing rules. This is particularly useful when building RESTful application. You can use standard HTTP Verb (GET, PUT, POST, DELETE) or custom HTTP Verb (e.g: PURGE). HTTP Verb rule is case insensitive. All you need to do is add array index using HTTP Verb rule. Example:

    $route['products']['put'] = 'product/insert';

In the above example, a PUT request to URI "products" would call the "product" controller class and "insert" method.

    $route['products/(:num)']['DELETE'] = 'product/delete/$1';

A DELETE request to URL with "products" as first segment and a number in the second will be remapped to the "product" class and "delete" method passing in the match as a variable to the method.

    $route['products/([a-z]+)/(\d+)']['get'] = 'product/$1/$2';

A GET request to a URI similar to products/shirts/123 would call the "product" controller class and "shirt" method with number as method parameter.

Using HTTP Verb is optional, so if you want any HTTP Verb to be handled in one rule You could just write your routing rule without HTTP Verb. Example:

    $route['product'] = 'product';

This way, all incoming request using any HTTP method containing the word "product" in the first segment will be remapped to "product" class.

The quick solution is to update system/core/Router.php with the changes from that specific commit: https://github.com/EllisLab/CodeIgniter/commit/af709d6ebe6ca75913d7a9eedb4fdcd76be45c50.

Also, the pull request references Pigeon library for handling advanced routing configurations.

这篇关于codeigniter的HTTP方法的定制路线2.1.4支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆