How i do to get resource based on filter parameter :
As Example : .../api/book?author=X
If an complete example i will be happy !
Based on FOSRestBundle, you can use QueryParam annotation and ParamFetcher as follow,
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 ...
}
requirements,
param_fetcher_listener: true in the bundle's configuration in your app/config/config.yml file.public function getActualitesAction(Request $request, ParamFetcherInterface $paramFetcher) { $offset = $paramFetcher->get('offset'); $offset = null == $offset ? 0 : $offset; $limit = $paramFetcher->get('limit'); $ville = $paramFetcher->get('ville'); return $this->container->get('genius_profile.actualite.handler')->all($limit, $offset,$ville); }public function all($limit = 5, $offset = 0,$ville) { return $this->repository->findBy(array(), null, $limit, $offset,$ville); }public function all($limit = 5, $offset = 0,$ext) { return $this->repository->findBy(array(), null, $limit, $offset,$ext); } but did not work :/