[英]Symfony2 REST bundle : Filter Parameter
我如何根据过滤器参数获取资源:
例如: ... / api / book?author = X
如果有一个完整的例子,我会很高兴的!
基于FOSRestBundle ,您可以按以下方式使用QueryParam批注和ParamFetcher ,
use FOS\RestBundle\Controller\FOSRestController;
// ...
use FOS\RestBundle\Request\ParamFetcher;
use FOS\RestBundle\Controller\Annotations\QueryParam;
class BookController extends FOSRestController
{
/**
*
* @QueryParam(name="author", description="the author of the book")
*/
public function getBookAction(ParamFetcher $paramFetcher)
{
$author = $paramFetcher->get('author'); // Can then be used to filter books on author
// do something ...
}
要求,
app/config/config.yml
文件中捆绑软件的配置中添加param_fetcher_listener: true
来启用param param_fetcher_listener: true
侦听器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.