该文档有一个项目 Operation ( https://api-platform.com/docs/core/operations#creating-custom-operations-and-controllers ) 的示例。如何为收集操作做同样的事情?这就是所做的,但它不起作用。
// src/AppBundle/Entity/Book.php
* @ApiResource(collectionOperations={
* "get",
* "special"={"route_name"="book_special"}
* })
class Book
{
...
}
路由:
book_special:
path: '/books/special'
methods: ['POST']
defaults:
_controller: 'AppBundle:Book:special'
_api_resource_class: 'AppBundle\Entity\Book'
_api_collection_operation_name: 'special'
和控制器:
class BookController extends Controller
{
public function specialAction(Book $book, Request $request)
{
//in the variable $book there is nothing
//in the variable $request there is nothing
return $book;
}
}
控制器中如何接收数据api请求?