serebro/phalcon-rest
最新稳定版本:0.2
Composer 安装命令:
composer require serebro/phalcon-rest
包简介
phalcon rest api
README 文档
README
Configuration
Services (config/services.php)
$di = new \Phalcon\DI\FactoryDefault(); new \PhalconRest\ServiceProvider($di);
Router (config/routes.php)
$router = new \Phalcon\Mvc\Router(false); $router->removeExtraSlashes(true); $router->setDefaultNamespace('Controllers'); $rest = new \PhalconRest\Mvc\Router\RestGroup(); $rest->setNamespace('Controllers\Api') ->setPrefix('api/') ->setIdFilter('[0-9]+') ->initDefault(); $router->mount($rest); return $router;
Controller
ExampleController.php
<?php namespace Controllers\Api; class OrdersController extends \PhalconRest\Mvc\ControllerBase { public function initialize() { $this->rest->setViewsDir('api/'); } public function indexAction() { $this->view->total = Order::count(); $this->view->orders = Order::find(); } public function getAction() { $order_id = $this->dispatcher->getParam('id'); $order = Order::findFirst($order_id); if (!$order) { throw new \PhalconRest\Exception\NotFound(); } $this->rest->order = $order; $this->rest->pick('orders/_item'); } }
Response
<?php /* app/rest/orders/index.php */ return function ($params) { $items = []; foreach ($params['orders'] as $order) { $items[] = $this->partial('orders/_item', ['order' => $order]); } return [ 'results' => $items ]; };
<?php /* app/rest/orders/_item.php */ return function ($params) { return [ 'id' => $order->id, 'createdAt' => $order->created_at, 'userId' => $order->user_id, 'sum' => $order->sum, ]; };
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-02