https://github.com/onanying/ci3-restful-controller
为 CodeIgniter3 框架扩展 RESTful API 的支持,RESTful 控制器基类。
https://github.com/onanying/ci3-restful-controller
api codeigniter controller restful
Last synced: 2 months ago
JSON representation
为 CodeIgniter3 框架扩展 RESTful API 的支持,RESTful 控制器基类。
- Host: GitHub
- URL: https://github.com/onanying/ci3-restful-controller
- Owner: onanying
- Created: 2017-05-19T15:04:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-19T15:44:24.000Z (almost 8 years ago)
- Last Synced: 2025-01-05T09:42:22.488Z (4 months ago)
- Topics: api, codeigniter, controller, restful
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: News.php
Awesome Lists containing this project
README
## 简介
为 CodeIgniter 框架扩展 RESTful API 的支持,RESTful 控制器基类。
## 路由规则
标准请求方法
请求类型 | 路由规则 | 对应操作方法
---|---|---
GET | blog | index
GET | blog/create | create
POST | blog | save
GET | blog/:id | read
GET | blog/:id/edit | edit
PUT | blog/:id | update
DELETE | blog/:id | deletePOST模拟PUT/DELETE
请求类型 | 路由规则 | 对应操作方法
---|---|---
POST | blog/:id/put | update
POST | blog/:id/delete | delete## 使用说明
### 第 1 步
将以下两个文件 copy 至 `application/core` 目录中。
```
MY_Controller.php
REST_Controller.php
```> MY_Controller.php 的前缀要与 config.php 内的 subclass_prefix 配置项一至。
### 第 2 步
按如下范例建立你的控制器:
```php
class News extends REST_Controller
{public function _index()
{
$this->response(['errcode' => 0, 'errmsg' => 'index']);
}public function _create()
{
$this->response(['errcode' => 0, 'errmsg' => 'create']);
}public function _save($data)
{
$this->response(['errcode' => 0, 'errmsg' => 'save', 'data' => $data]);
}public function _read($id)
{
$this->response(['errcode' => 0, 'errmsg' => 'read', 'id' => $id]);
}public function _edit($id)
{
$this->response(['errcode' => 0, 'errmsg' => 'edit', 'id' => $id]);
}public function _update($id, $data)
{
$this->response(['errcode' => 0, 'errmsg' => 'update', 'id' => $id, 'data' => $data]);
}public function _delete($id)
{
$this->response(['errcode' => 0, 'errmsg' => 'delete', 'id' => $id]);
}// 析构
public function __destruct()
{
// 回收PUT上传的临时文件
parent::__destruct();
}}
```