| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

用于CodeIgniter的一个完整RESTful服务器实现:CodeIgniter Rest Server

用于CodeIgniter的一个完整RESTful服务器实现,只用到一个库,一个配置文件和一个控制器。

Requirements

  1. PHP 5.4 or greater
  2. CodeIgniter 3.0+

Note: for 1.7.x support download v2.2 from Downloads tab

Installation

Drag and drop the application/libraries/Format.php and application/libraries/REST_Controller.php files into your application's directories. To userequire_onceit at the top of your controllers to load it into the scope. Additionally, copy the rest.php file from application/config in your application's configuration directory.

Handling Requests

When your controller extends fromREST_Controller, the method names will be appended with the HTTP method used to access the request. If you're making an HTTPGETcall to/books, for instance, it would call aBooks#index_get()method.

This allows you to implement a RESTful interface easily:

class Books extends REST_Controller  {    public function index_get()    {      // Display all books    }      public function index_post()    {      // Create a new book    }  }

REST_Controlleralso supportsPUTandDELETEmethods, allowing you to support a truly RESTful interface.

Accessing parameters is also easy. Simply use the name of the HTTP verb as a method:

$this->get('blah'); // GET param  $this->post('blah'); // POST param  $this->put('blah'); // PUT param

The HTTP spec for DELETE requests precludes the use of parameters. For delete requests, you can add items to the URL
public function index_delete($id)  {      $this->response([          'returned from delete:' => $id,      ]);  }

If query parameters are passed via the URL, regardless of whether it's a GET request, can be obtained by the query method:

$this->query('blah'); // Query param

项目主页:http://www.open-open.com/lib/view/home/1442241855618

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1442241855618.html
CodeIgniter Web框架 CodeIgniter Rest Server