繁体   English   中英

Symfony2 REST捆绑包:过滤器参数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM