How to paginate the symfony list data
This is for listing the data in tabular format.
Module fileĀ = <module_name/actions/actions.class.php>
/* 10 is constraint for list number of items */
$pager = new sfPropelPager(‘ClkPerPackageType’, 10);
/* this will get the page items which is defined in frontend/config/app.yml */
$c = new Criteria();
//$c->add(ClkPerPackageTypePeer::STATUS,’1′);
$pager->setPage($this->getRequestParameter(‘page’, 1));
$pager->setCriteria($c);
$pager->init();
$this->page_counter = ($this->getRequestParameter(‘page’, 1)==1) ? 1 : ((($this->getRequestParameter(‘page’)-1)*10)+1);
$this->ClkProductCompounds = $pager;
View fileĀ = <templates/methodSuccess.php>
foreach ($ClkProductCompounds->getResults() as $cpc): ?>
<tr align=”left” <?php if($page_counter%2 ==0){ echo”style=’background-color:#e9e9e9;'”;}?>>
<td><?php echo $page_counter;?></td>
<td><?php echo $id = $cpc->getPerPackageTypeCode() ?></td>
<td><?php echo $cpc->getPerPackageTypeName(); ?></td>
<td><a href=”<?php echo url_for(‘PerPackageType/list?edit=’ . $id ); ?>”>edit</a></td>
</tr>
<?php
$page_counter++;
endforeach;
Pagination list. It creates the page link to the fist list and page number.
<div class=”Paging”>
<?php if ($ClkProductCompounds->haveToPaginate()): ?>
<?php echo link_to(‘«’, ‘PerPackageType/list?page=1’) ?>
<?php echo link_to(‘<’, ‘PerPackageType/list?page=’.$ClkProductCompounds->getPreviousPage()) ?>
<?php foreach ($ClkProductCompounds->getLinks() as $page): ?>
<?php echo link_to_unless($page == $ClkProductCompounds->getPage(), $page, ‘PerPackageType/list?page=’.$page) ?>
<?php echo ($page != $ClkProductCompounds->getCurrentMaxLink()) ? ‘-‘ : ” ?>
<?php endforeach; ?>
<?php echo link_to(‘>’, ‘PerPackageType/list?page=’.$ClkProductCompounds->getNextPage()) ?>
<?php echo link_to(‘»’, ‘PerPackageType/list?page=’.$ClkProductCompounds->getLastPage()) ?>
<?php endif; ?>
</div>