zoukankan      html  css  js  c++  java
  • symfony分页实现方法

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

    2. 用composer下载

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

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

          public functionregisterBundles() {   

                $bundles = [                     new   KnpBundlePaginatorBundleKnpPaginatorBundle(),         ];    

             }  

    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) }}
    

      

     

     

  • 相关阅读:
    通道符和xargs命令
    Linux中sudo的用法
    yum中查找程序由哪个包提供
    SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled)
    Centos7中一次性安装开发者工具
    数据库设计步骤
    校验表单demo
    javascript之DOM总结
    javascript之BOM对象总结
    javascript之正则表达式
  • 原文地址:https://www.cnblogs.com/zgaspnet/p/7640330.html
Copyright © 2011-2022 走看看