public function searchAction(Request $request) { if ($request->getMethod() == 'GET') { $keywords = $request->get('keywords'); if ($keywords != '') { $order_by = ''; $em = $this->get('doctrine.orm.entity_manager'); $repository = $em->getRepository('Acme\\StoreBundle\\Entity\\Product'); $languagesCount = $repository->getIdCount(); $paginator = new Product($languagesCount); $strPaginator = $paginator->RenderPaginator(); $sort_direction = "asc"; $products = $em->createQueryBuilder()->select('b')->from('AcmeStoreBundle:Product', 'b')->where("b.name = :name")->setParameter('name', $keywords)->addOrderBy('b.id', 'DESC')->getQuery()->getResult(); return $this->render('AcmeStoreBundle:Default:index.html.twig', array('products' => $products, 'sort_dir' => $sort_direction, 'paginator' => $strPaginator)); } else { $order_by = ''; $em = $this->get('doctrine.orm.entity_manager'); $repository = $em->getRepository('Acme\\StoreBundle\\Entity\\Product'); $languagesCount = $repository->getIdCount(); $paginator = new Product($languagesCount); $strPaginator = $paginator->RenderPaginator(); $sort_direction = "asc"; $products = $repository->getProductListWithPagination($sort_direction, $paginator->getOffset(), $paginator->getLimit()); return $this->render('AcmeStoreBundle:Default:index.html.twig', array('products' => $products, 'sort_dir' => $sort_direction, 'paginator' => $strPaginator)); } } }
/** * {@inheritDoc} */ public function getOffset() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getOffset', array()); return parent::getOffset(); }