Friday, February 25, 2011

Paging in Symfony

In this tutorial we will learn how to implement Paging in Symfony, the process is fairly simple and easy to implement, just a little know how to PHP, Symfony and Doctrine is required.
First the code we will write in Controller or Symfony module Action class.
public function executePaging(sfWebRequest $request){

        $results_per_page=10;
        $set_first_page=1;

        $this->pagination = new sfDoctrinePager('User', $results_per_page);
        $this->pagination->setQuery(Doctrine::getTable('User')->createQuery('u'));
        $this->pagination->setPage($request->getParameter('page', $set_first_page));
        $this->pagination->init();
        
    }
now the code we write in View or the ethodNameSuccess in our case PagingSuccess.php
<?php foreach ($pagination->getResults() as $users): ?>

<?php endforeach; ?> 
<?php echo $users->getId(); ?> <?php echo $users->getFirstName(); ?> <?php echo $users->getLastName(); ?> <?php echo $users->getEmail(); ?>
<?php echo link_to('<<', 'myModule/Paging?page='.$pagination->getFirstPage()) ?>
<?php if ($pagination->haveToPaginate()): ?> <?php $links = $pagination->getLinks(); foreach ($links as $page): ?>
<?php echo ($page == $pagination->getPage()) ? $page : link_to($page, 'myModule/Paging?page='.$page) ?>
<?php endforeach ?> <?php endif ?>
<?php echo link_to('>>', 'myModule/Paging?page='.$pagination->getLastPage()) ?>
try to implement it and you will see its very easy :)

1 comments:

JIbu said...

Good

Post a Comment

 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems