php - Dynamic limit per page Knp Pagination -


i need straightforward solution dynamically set number of records per page knp pagination bundle.

i read page records per page allow user choose - codeigniter pagination dynamically set per page limits , know need drop down hyperlink inside each item send request server , server use parameter on request set limit per page on knp pagination bundle. don't know how handle actions on server , , more harder me how create items on drop down related total number on query.

my controller:

public function indexaction() {        $page_title = util::getformattedpagetitle("customers");      $em    = $this->get('doctrine.orm.entity_manager');     $dql   = "select customersbundle:customer a.enable = 1 order a.id";     //$query = $em->createquery($dql);     //$customers = $query->execute();      $query = $em->createquery($dql);      $paginator  = $this->get('knp_paginator');     $pagination = $paginator->paginate(         $query,         $this->get('request')->query->get('page', 1)/*page number*/,         3/*limit per page*/     );       // parameters template     return $this->render('customersbundle:default:index.html.twig', array(         'page_title' => $page_title,         'pagination' => $pagination,         'image_path' => customersconstants::$customers_image_thumb_path     )); } 

and view code is:

    {% extends '::base.html.twig' %}  {% block title %}     {{ page_title }} {% endblock %}  {% block body %}     <h1>         {{ "customers" }}     </h1>     <br />     {% customer in pagination %}     <a href="{{ customer.url }}" target="_blank">         <div dir="rtl" class="st_simple_box" id="customer{{customer.id}}" >             <table cellpadding="0" cellspacing="0" width="100%">                 <tr>                     <td style="vertical-align: top; width: 115px;">                         {% if customer.imagename not empty %}                             <img class="newsimage" src="{{asset(image_path) ~ customer.imagename}}" alt="no image/>                         {% else %}                             <img class="newsimage" src="{{asset('images/vakil_default_small.png') ~ customer.imagename}}" alt="no image"/>                         {% endif %}                     </td>                     <td style="text-align: center;">                         <p><span style="font-family: tahoma;">{{customer.titlefa}}</span></p>                     </td>                     <td style="text-align: justify;">                         <p><span style="font-family: tahoma;">{{customer.descriptionfa}}</span></p>                     </td>                 </tr>             </table>         </div>     </a>     {% endfor %}     <div class="navigation">         <span>         {{ knp_pagination_render(pagination) }}         </span>         <!--here drop down html code-->     </div>     <br />  {% endblock %} 

**

edited on 12 march 2014

   ||||    ||||    ||||   \\\///    \\//     \/ 

is there way set maxitemperpage on cookie have integrated variable , use variable or change while knp pagination showed on twig file.

the answer correct because of used pagination in many bundles paginate between entities need integrate variable change of them. use answer , customize sliding.html.twig on knp pagination reach code "customized_sliding.html.twig"

<div class="ui small pagination menu">     <div style="clear: both;">         {% if pagecount > 1 %}             <div class="pagination" style="float: right;">                 {% if first defined , current != first %}                     <a href="{{ path(route, query|merge({(pageparametername): first})) }}" class="small icon item">                         <i class="small double angle right icon"></i>                     </a>                 {% endif %}                  {% if previous defined %}                     <a href="{{ path(route, query|merge({(pageparametername): previous})) }}" class="small icon item">                         <i class="small angle right icon"></i>                     </a>                 {% endif %}                  {% page in pagesinrange %}                     {% if page != current %}                         <a href="{{ path(route, query|merge({(pageparametername): page})) }}" class="small item">                             {{ page }}                         </a>                     {% else %}                         <a class="small active item">                             {{ page }}                         </a>                     {% endif %}                 {% endfor %}                  {% if next defined %}                     <a href="{{ path(route, query|merge({(pageparametername): next})) }}" class="small icon item">                         <i class="small angle left icon"></i>                     </a>                 {% endif %}                  {% if last defined , current != last %}                     <a href="{{ path(route, query|merge({(pageparametername): last})) }}" class="small icon item">                         <i class="small double angle left icon"></i>                     </a>                 {% endif %}             </div>         {% endif %}         <div style="float: left;">             <select name="maxitemperpage" id="maxitemperpage">                 <option selected="true" style="display:none;">number per page</option>                 <option id="10">5</option>                 <option id="20">10</option>                 <option id="30">20</option>             </select>         </div>     </div>     <script type="text/javascript">         //on select change, navigate indexaction , send parameter maxitemperpage         $('#maxitemperpage').change(function(){             {% set currentpath = path(app.request.attributes.get('_route')) %}             var url = "{{path(app.request.attributes.get('_route'),{'maxitemperpage': '_itemnum'})}}";             var item = $('#maxitemperpage').find(":selected").text();             jquery(location).attr('href', url.replace('_itemnum',item ));         });     </script> </div> 

i want fetch , store maxitemperpage cookie there no need change bundles code. example in controller don't know have fetch $maxitemperpage cookie

$pagination = $paginator->paginate(             $query,             $this->get('request')->query->get('page', 1)/*page number*/,             $maxitemperpage/*limit per page*/         ); 

and need change value of maxitemperpage on cookie changing value of html tag javascript , redirect page same controller , no need send maxitemperpage controller.

this can done (if understood well)

public function indexaction($maxitemperpage=20) {        $page_title = util::getformattedpagetitle("customers");      $em    = $this->get('doctrine.orm.entity_manager');     $dql   = "select customersbundle:customer a.enable = 1 order a.id";     //$query = $em->createquery($dql);     //$customers = $query->execute();      $query = $em->createquery($dql);      $paginator  = $this->get('knp_paginator');     $pagination = $paginator->paginate(         $query,         $this->get('request')->query->get('page', 1)/*page number*/,         $maxitemperpage /*limit per page*/     );       // parameters template     return $this->render('customersbundle:default:index.html.twig', array(         'page_title' => $page_title,         'pagination' => $pagination,         'image_path' => customersconstants::$customers_image_thumb_path     )); } 

in view

   {% extends '::base.html.twig' %}      {% block title %}         {{ page_title }}     {% endblock %} {% block javascript%} <script type="text/javascript">  //on select change, navigate indexaction , send parameter maxitemperpage $('#maxitemperpage').change(function(){  var url = '{{path('controller_index_route','maxitemperpage':_itemnum)}}'; var item = $('#maxitemperpage').find(":selected").text();  window.location.href = url.replace('_itemnum',item ); })  </script>     {% endblock %}      {% block body %}         <h1>             {{ "customers" }}         </h1>         <br />         {% customer in pagination %}         <a href="{{ customer.url }}" target="_blank">             <div dir="rtl" class="st_simple_box" id="customer{{customer.id}}" >                 <table cellpadding="0" cellspacing="0" width="100%">                     <tr>                         <td style="vertical-align: top; width: 115px;">                             {% if customer.imagename not empty %}                                 <img class="newsimage" src="{{asset(image_path) ~ customer.imagename}}" alt="no image/>                             {% else %}                                 <img class="newsimage" src="{{asset('images/vakil_default_small.png') ~ customer.imagename}}" alt="no image"/>                             {% endif %}                         </td>                         <td style="text-align: center;">                             <p><span style="font-family: tahoma;">{{customer.titlefa}}</span></p>                         </td>                         <td style="text-align: justify;">                             <p><span style="font-family: tahoma;">{{customer.descriptionfa}}</span></p>                         </td>                     </tr>                 </table>             </div>         </a>         {% endfor %}         <div class="navigation">             <span>             {{ knp_pagination_render(pagination) }}             </span>             <!--here drop down html code-->         </div>         <br /> <select name="maxitemperpage" id="maxitemperpage"> <option id="10">10</option> <option id="20">20</option> <option id="30">30</option> </select>      {% endblock %} 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -