public function searchAction(Request $request)
    {
        $response = $this->getCacheTimeKeeper()
            ->getResponse(['AnimeDbCatalogBundle:Item', 'AnimeDbCatalogBundle:Storage']);
        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        /* @var $form Form */
        $form = $this->createForm('animedb_catalog_search', new SearchEntity())->handleRequest($request);
        $pagination = null;
        $result = ['list' => [], 'total' => 0];

        if ($form->isValid()) {
            /* @var $controls ListControls */
            $controls = $this->get('anime_db.item.list_controls');

            // current page for paging
            $current_page = $request->get('page', 1);
            $current_page = $current_page > 1 ? $current_page : 1;

            // get items limit
            $limit = $controls->getLimit($request->query->all());

            // do search
            $result = $this->get('anime_db.item.search')->search(
                $form->getData(),
                $limit,
                ($current_page - 1) * $limit,
                $controls->getSortColumn($request->query->all()),
                $controls->getSortDirection($request->query->all())
            );

            if ($limit) {
                // build pagination
                $that = $this;
                $query = $request->query->all();
                unset($query['page']);
                $pagination = $this->get('anime_db.pagination')
                    ->create(ceil($result['total'] / $limit), $current_page)
                    ->setPageLink(function ($page) use ($that, $query) {
                        return $that->generateUrl('home_search', array_merge($query, ['page' => $page]));
                    })
                    ->setFirstPageLink($this->generateUrl('home_search', $query))
                    ->getView();
            }
        }

        return $this->render('AnimeDbCatalogBundle:Home:search.html.twig', [
            'form' => $form->createView(),
            'items' => $result['list'],
            'total' => $result['total'],
            'pagination' => $pagination,
            'searched' => (bool) $request->query->count(),
        ], $response);
    }
public function searchAction(Request $request)
    {
        $response = $this->getCacheTimeKeeper()
            ->getResponse(['AnimeDbCatalogBundle:Item', 'AnimeDbCatalogBundle:Storage']);
        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        /* @var $form Form */
        $form = $this->createForm('animedb_catalog_search', new SearchEntity())->handleRequest($request);
        $pagination = null;
        $result = ['list' => [], 'total' => 0];

        if ($form->isValid()) {
            /* @var $controls ListControls */
            $controls = $this->get('anime_db.item.list_controls');

            // current page for paging
            $current_page = $request->get('page', 1);
            $current_page = $current_page > 1 ? $current_page : 1;

            // get items limit
            $limit = $controls->getLimit($request->query->all());

            // do search
            $result = $this->get('anime_db.item.search')->search(
                $form->getData(),
                $limit,
                ($current_page - 1) * $limit,
                $controls->getSortColumn($request->query->all()),
                $controls->getSortDirection($request->query->all())
            );

            if ($limit) {
                // build pagination
                $that = $this;
                $query = $request->query->all();
                unset($query['page']);
                $pagination = $this->get('anime_db.pagination')
                    ->create(ceil($result['total'] / $limit), $current_page)
                    ->setPageLink(function ($page) use ($that, $query) {
                        return $that->generateUrl('home_search', array_merge($query, ['page' => $page]));
                    })
                    ->setFirstPageLink($this->generateUrl('home_search', $query))
                    ->getView();
            }
        }

        return $this->render('AnimeDbCatalogBundle:Home:search.html.twig', [
            'form' => $form->createView(),
            'items' => $result['list'],
            'total' => $result['total'],
            'pagination' => $pagination,
            'searched' => (bool) $request->query->count(),
        ], $response);
    }
public function searchAction ( Request $ request ) { $ response = $ this -> getCacheTimeKeeper ( ) -> getResponse ( [ 'AnimeDbCatalogBundle:Item' , 'AnimeDbCatalogBundle:Storage' ] ) ; // response was not modified for this request if ( $ response -> isNotModified ( $ request ) ) { return $ response ; } /* @var $form Form */ $ form = $ this -> createForm ( 'animedb_catalog_search' , new SearchEntity ( ) ) -> handleRequest ( $ request ) ; $ pagination = null ; $ result = [ 'list' => [ ] , 'total' => 0 ] ; if ( $ form -> isValid ( ) ) { /* @var $controls ListControls */ $ controls = $ this -> get ( 'anime_db.item.list_controls' ) ; // current page for paging $ current_page = $ request -> get ( 'page' , 1 ) ; $ current_page = $ current_page > 1 ? $ current_page : 1 ; // get items limit $ limit = $ controls -> getLimit ( $ request -> query -> all ( ) ) ; // do search $ result = $ this -> get ( 'anime_db.item.search' ) -> search ( $ form -> getData ( ) , $ limit , ( $ current_page - 1 ) * $ limit , $ controls -> getSortColumn ( $ request -> query -> all ( ) ) , $ controls -> getSortDirection ( $ request -> query -> all ( ) ) ) ; if ( $ limit ) { // build pagination $ that = $ this ; $ query = $ request -> query -> all ( ) ; unset ( $ query [ 'page' ] ) ; $ pagination = $ this -> get ( 'anime_db.pagination' ) -> create ( ceil ( $ result [ 'total' ] / $ limit ) , $ current_page ) -> setPageLink ( function ( $ page ) use ( $ that , $ query ) { return $ that -> generateUrl ( 'home_search' , array_merge ( $ query , [ 'page' => $ page ] ) ) ; } ) -> setFirstPageLink ( $ this -> generateUrl ( 'home_search' , $ query ) ) -> getView ( ) ; } } return $ this -> render ( 'AnimeDbCatalogBundle:Home:search.html.twig' , [ 'form' => $ form -> createView ( ) , 'items' => $ result [ 'list' ] , 'total' => $ result [ 'total' ] , 'pagination' => $ pagination , 'searched' => ( bool ) $ request -> query -> count ( ) , ] , $ response ) ; }
Search item.

@param Request $request

@return Response
Search item .