目前,我在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,
],
],
],
],
],