Skip to content

Instantly share code, notes, and snippets.

@memphys
Created February 24, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save memphys/ac6777bdef81e5ca0237 to your computer and use it in GitHub Desktop.
Save memphys/ac6777bdef81e5ca0237 to your computer and use it in GitHub Desktop.
<?php
namespace App\ApiBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use FOS\RestBundle\Controller\Annotations\View;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Request;
class ProductController extends BaseController
{
/**
* @View(serializerGroups={"productList"})
* @Route("/products")
* @Method({"GET", "OPTIONS"})
*
* @ApiDoc(
* section="Продукты",
* description="Получение страниц по id каталога",
* parameters={
* {"name"="shop", "dataType"="integer", "description"="ID магазина", "required"=false, "readonly"=false}
* },
* output={
* {"items", "array", "Product"},
* }
* )
*/
public function listAction(Request $request)
{
$repository = $this->getDoctrine()->getManager()->getRepository('AppBundle:Product');
$requestQuery = $this->get('request');
$perPageCount = $requestQuery->get('perPage', 100);
$query = $repository->getProductsByParams([
'store' => $request->query->get('shop'),
]);
$pagination = $this->get('knp_paginator')->paginate($query, $requestQuery->get('page', 1), $perPageCount);
return [
'items' => $pagination->getItems(),
'pagination' => $pagination->getPaginationData()
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment