3

i'm working on a symfony project and needed to create a paging system for long lists. I used sfPropelPager plugin to generate them. I'm using it this way:

I print all the pages in diferent <div> tags and only set visible the first. Then whith a javascript function, i show the other pages when clicking on next, prev, ... buttons.

the function i use to generate the pages is this: `

    $pager = new sfPropelPager('SysLogTbl',sfConfig::get('sfPropelPagerLines'));
    $c = new Criteria();
    $c->add('codigo_maestro',$this->getCodigoMaestro());
    $c->add('codigo_registro',$id);
    $c->addDescendingOrderByColumn('fecha_log');
    $pager->setCriteria($c);
    $pager->init();
    return $pager;`

and the view code is:

        foreach($pager->getLinks() as $page){

        echo'<div id="logpage'.$page.'" class="logpages" style="width:100%;';
        if($page!=1){echo ' display:none';}
        echo '">';

        $pager->setPage($page);
        $pager->init();
        $results= $pager->getResults();

        echo '<table class="none_list" id="list">';
        echo "<thead>";
        echo "<td width='8%'>Usuario</td><td width='8%'>Acci&oacute;n</td>";
        echo "<td width='13%'>Campo</td><td width='25%'>Valor Antiguo</td>";
        echo"<td width='25%'>Nuevo valor</td><td width='21%'>TimeStamp</td>";
        echo "</thead>";
        foreach($results as $log){
            echo '<tr id="'.$log->getCodigoLog().'" >';

            < here goes each entry in the page display, not relevant >


        }
        echo '</table>';

        echo "<div style='float:left'>";
        echo image_tag('first.png',array('class'=>"first"));
        echo image_tag('previous.png',array('class'=>"previous"));
        echo "</div>";
        foreach($lista->getLinks() as $page){
            echo "<div class='logindex' id='".$page."' style='float:left; cursor:pointer'>";
            if($page == $lista->getPage()){
                echo "<b>".$page."</b>";
            }else{
                echo $page;
            }
            echo "</div>";
        }
        echo image_tag('next.png',array('class'=>"next"));
        echo image_tag('last.png',array('class'=>"last"));
    echo '</div>';
    $lista->setCursor($lista->getNextPage());

}
$lista->setCursor($lista->getFirstPage());?>

The problem is sfPropelPager only generates at most 5 pages.

Do you know where must i configure this to show all the pages?? thank you!

Andreu Ramos
  • 2,858
  • 2
  • 25
  • 36
  • 1
    Could you please add some "relevant" code? The controller part where you create the pager and the view part where you render the pager? I'm curious about your items per page setting (`$pager->getMaxPerPage()`) and number of results (`$pager->count()`). – Grad van Horck Nov 02 '11 at 14:49

2 Answers2

3

If you check the source of sfPager you'll see it has a $nb_links parameter that tells how many links you want. The default is 5.

Maerlyn
  • 33,687
  • 18
  • 94
  • 85
0

Pagination is very straightforward - here is a great example on the Jobeet tutorial -> http://www.symfony-project.org/jobeet/1_4/Propel/en/07#chapter_07_list_pagination

Manse
  • 37,765
  • 10
  • 83
  • 108
  • i did the tutorial long ago, and revised when i detected this behaviour, and i didn't found the solution – Andreu Ramos Nov 02 '11 at 15:03
  • @AndreuHeineken Where do you set the page in your action ? -> $this->pager->setPage($request->getParameter('page', 1)); – Manse Nov 02 '11 at 15:06
  • @AndreuHeineken if you follow the documentation is works - if you start moving things around - like putting code in the view ... it doesn't .... – Manse Nov 02 '11 at 15:07
  • (1) the first piece of code is not in the action, is in a model file, so $this->pager is not necessary. (2) I dont set the page in the action, i generate them all. What does that to do with my problem? (3) My needs are not the same that solves the documentation example, so i can't follow it at 100%. Tnank you. – Andreu Ramos Nov 02 '11 at 15:14