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

      

     

     

  • 相关阅读:
    lua面向对象(定义与调用)
    luastring(字符串)
    luatable(表)
    lua面向对象(创建与实例化)
    pandas安装方法(常规安装失败解决方法)
    lua循环
    windows常用命令schtasks
    ios UI自动化 appium参数配置
    ios UI自动化环境配置
    jmeter进行websocket 通信
  • 原文地址:https://www.cnblogs.com/zgaspnet/p/7640330.html
Copyright © 2011-2022 走看看