php - REST API zend 框架 2 迁移到 REST API zend 框架 3
问题描述
目前,我在 Zend Framework 2 中使用 REST API。现在,我想在 ZF3 中迁移 ZF2 REST API。我检查了 ZF3 的 REST API,但没有发现任何东西。
ZF3 REST API 没有文档。
是否可以使用 ZF3 构建 REST API?如果我有任何例子,那就太好了。
解决方案
检查:https ://github.com/multidots/zf3-rest-api或
创建你的休息控制器:
class AlbumRestController extends AbstractRestfulController
{
public function get($id)
{
return new JsonModel(array("id"));
}
public function getList()
{
return new JsonModel(
array(
array("id"),
array("id"),
array("id")
));
}
}
添加到你的module.config.php:
'controllers' => [
'factories' => [
Controller\AlbumRestController::class => InvokableFactory::class,
],
],
最后定义你的路线:
'router' => [
'routes' => [
'album-rest' => [
'type' => Segment::class,
'options' => [
'route' => '/album-rest[/:id]',
'constraints'=> [
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\AlbumRestController::class,
],
],
],
],
],
推荐阅读
- ruby-on-rails - 迁移中的 Rails 活动记录序列化
- javascript - 如何在控制台日志中查看所选选项与其他选项的组合?
- android - 无法在弹出活动中编辑 EditText
- amazon-s3 - AWS-S3 orb - Circle CI - 意外参数:参数
- d3.js - 使用d3鼠标悬停时如何使路径始终填充绿色
- reactjs - 重定向在 Accounts.createUser() 中不起作用
- javascript - 如何在导航器中将不同的道具传递到不同的屏幕?
- reactjs - 在 webworker 中访问 axios 报错 ReferenceError: axios__WEBPACK_IMPORTED_MODULE_0___default is not defined
- javascript - Vuejs 获取组件 HTML 并通过 ajax POST 发送
- c# - XML 保留结构