Knp\Bundle\KnpBundlesBundle\Controller\BundleController::searchByKeywordAction PHP Method

searchByKeywordAction() public method

public searchByKeywordAction ( Request $request, $slug )
$request Symfony\Component\HttpFoundation\Request
    public function searchByKeywordAction(Request $request, $slug)
    {
        $format = $request->getRequestFormat();
        $query = $this->getRepository('Bundle')->queryByKeywordSlug($slug);
        $paginator = $this->getPaginator($query, $request->query->get('page', 1), $request->query->get('limit', 10));
        if ('json' === $format) {
            $result = array('results' => array(), 'total' => $paginator->getNbResults());
            /* @var $bundle Bundle */
            foreach ($paginator as $bundle) {
                $result['results'][] = $bundle->toSmallArray() + array('url' => $this->generateUrl('bundle_show', array('ownerName' => $bundle->getOwnerName(), 'name' => $bundle->getName()), true));
            }
            if ($paginator->hasPreviousPage()) {
                $result['prev'] = $this->generateUrl('bundle_keyword', array('page' => $paginator->getPreviousPage(), 'limit' => $request->query->get('limit'), '_format' => 'json'), true);
            }
            if ($paginator->hasNextPage()) {
                $result['next'] = $this->generateUrl('bundle_keyword', array('page' => $paginator->getNextPage(), 'limit' => $request->query->get('limit'), '_format' => 'json'), true);
            }
            return new JsonResponse($result);
        }
        $this->highlightMenu('bundles');
        $response = $this->render('KnpBundlesBundle:Bundle:searchByKeywordResults.html.twig', array('bundles' => $paginator, 'keywordSlug' => $slug));
        // caching
        $response->setPublic();
        $response->setSharedMaxAge(600);
        return $response;
    }