设为首页 加入收藏

TOP

symfony分页实现方法
2017-10-09 13:25:42 】 浏览:5312
Tags:symfony 实现 方法

1.symfony分页是要用到组件的,所以这里使用KnpPaginatorBundle实现翻页

2. 用composer下载

   在命令行中:  composer require "knplabs/knp-paginator-bundle"  

3.需要到框架里面注册该组件在项目下的app/Resources/AppKernel.php里面注册

      public functionregisterBundles() {   

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

         }  

4.控制器中的代码

class NewsController extends Controller
{
    /**
     * 2016-1-19
     * auth:lsf
     * 查询列表
     * @param   int $page   页数
     * @param   int $limit  显示条数
    */
    public function indexAction($page,$limit){
        $em = $this->getDoctrine()->getManager();
        $qb = $em->getRepository('AppBundle:DemoList')->createQueryBuilder('u');
//Appbundle是你的模块DemoList是你的表实体 u是别名后面可接条件

        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate($qb, $page,$limit);
        
        return $this->render('news/list.html.twig',['pagination' => $pagination]);
    }
}

5.路由

news_page:
  path: "/news/{page}/{limit}"
  defaults: {_controller: AppBundle:News:index,page:1,limit:2}

6.模板


{% for value in pagination %}
{{value.title}}{#直接就是值了#}
{% endfor %}
{{ knp_pagination_render(pagination) }}

  

 

 

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇仿百度文库网站源码,文库网站定.. 下一篇PHP引用(&)使用详解

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目