Symfony paging implementation method, symfony paging implementation

Source: Internet
Author: User

Symfony paging implementation method, symfony paging implementation

1. The components are used for symfony paging.KnpPaginatorBundleImplement Paging

2. Download with composer

In the command line: composer require "knplabs/knp-paginator-bundle"

3. register the component in the framework and register it in app/Resources/AppKernel. php of the project.

Public functionregisterBundles (){

$ Bundles = [new Knp \ Bundle \ PaginatorBundle \ KnpPaginatorBundle (),];

}

4. Code in the Controller

Class NewsController extends Controller {/*** 2016-1-19 * auth: lsf * query list * @ param int $ page pages * @ param int $ number of lines displayed by limit */public function indexAction ($ page, $ limit) {$ em = $ this-> getDoctrine ()-> getManager (); $ qb = $ em-> getRepository ('appbundle: demolist ') -> createQueryBuilder ('U '); // Appbundle is your module. DemoList is your table entity. u is the alias. The following conditions are available: $ paginator = $ this-> get ('knp _ paginator '); $ pagination = $ paginator-> paginate ($ qb, $ page, $ limit); return $ this-> render ('news/list.html. twig ', ['pagination' => $ pagination]);}

5. Routing

News_page: path: "/news/{page}/{limit}" defaults: {_ controller: AppBundle: News: index, page: 1, limit: 2}

6. Template


{% For value in pagination % }{{ value. title }{# is the value #}{% endfor % }{{ knp_pagination_render (pagination )}}

  

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.