cabreran/ci-hmvc-restserver
Composer 安装命令:
composer require cabreran/ci-hmvc-restserver
包简介
CodeIgniter HMVC Rest Server
README 文档
README
A fully RESTful server implementation for CodeIgniter HMVC using one library, one config file and one controller.
Requirements
- PHP 7.2 or greater
- CodeIgniter 3.1.11+
- HMVC
Installation
composer require cabreran/ci-hmvc-restserver
Usage
CodeIgniter HMVC Rest Server is available on Packagist (using semantic versioning), and installation via composer is the recommended way to install Codeigniter Rest Server. Just add this line to your composer.json file:
"cabreran/ci-hmvc-restserver": "^3.1"
or run
composer require cabreran/ci-hmvc-restserver
Note that you will need to copy rest.php to your config directory (e.g. application/config)
Step 1: Add this to your controller (should be before any of your code)
use Cabreran\RestServer\RestController;
Step 2: Extend your controller
class Example extends RestController
Basic GET example
Here is a basic example. This controller, which should be saved as Api.php, can be called in two ways:
http://domain/api/users/will return the list of all usershttp://domain/api/users/id/1will only return information about the user with id = 1
<?php defined('BASEPATH') OR exit('No direct script access allowed'); use Cabreran\RestServer\RestController; class Api extends RestController { function __construct() { // Construct the parent class parent::__construct(); } public function users_get() { // Users from a data store e.g. database $users = [ ['id' => 0, 'name' => 'John', 'email' => 'john@example.com'], ['id' => 1, 'name' => 'Jim', 'email' => 'jim@example.com'], ]; $id = $this->get( 'id' ); if ( $id === null ) { // Check if the users data store contains users if ( $users ) { // Set the response and exit $this->response( $users, 200 ); } else { // Set the response and exit $this->response( [ 'status' => false, 'message' => 'No users were found' ], 404 ); } } else { if ( array_key_exists( $id, $users ) ) { $this->response( $users[$id], 200 ); } else { $this->response( [ 'status' => false, 'message' => 'No such user found' ], 404 ); } } } }
cabreran/ci-hmvc-restserver 适用场景与选型建议
cabreran/ci-hmvc-restserver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 197 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cabreran/ci-hmvc-restserver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cabreran/ci-hmvc-restserver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 197
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-17