Symfony 1.4 Doctrine Pagination

Doctrine Pagination is made very simple .

public function executeIndex(sfWebRequest $request)
  {
    $this->pager = new sfDoctrinePager('TableName', sfConfig::get('app_max_jobs_on_homepage');
    $this->pager->setQuery(Doctrine::getTable('TableName')->createQuery('a'));
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
 }

Success page

<?php foreach ($pager->getResults() as $post): ?><div>
<?php if($post->getTitle()) { echo link_to($post->getTitle(), ‘news/fullstory?expand=’.$post->getId(),’class=”mhead”‘); } ?>
<?php if($post->getDn2()!=”) { echo image_tag($post->getDn2()); } ?>
<?php $content=$post->getContent();
$stripcontent=substr($content,” “,700);
echo $stripcontent;
?>
<div style=”display:block;” > <?php echo $post->getCreatedAt(); ?><?php echo link_to(“Full Story”, ‘news/fullstory?expand=’.$post->getId(),’class=”fullstory”‘) ?> <br /><br />
</div></div>
<?php endforeach ?>

pagination

<?php if ($pager->haveToPaginate())  { ?>

<div id=”navv”>

<?php echo link_to(‘Latest’, ‘news/index?page=’.$pager->getFirstPage(),’class=”pager”‘) ?>
<?php echo link_to(‘prev’, ‘news/index?page=’.$pager->getPreviousPage(),’class=”pager”‘ ) ?>
<?php $links = $pager->getLinks(); foreach ($links as $page): ?>
<?php echo ($page == $pager->getPage()) ? $page : link_to($page, ‘news/index?page=’.$page,’class=”pager”‘) ;?>
<?php if ($page != $pager->getCurrentMaxLink()): ?> <?php endif ?>
<?php endforeach ?>
<?php echo link_to(‘next’, ‘news/index?page=’.$pager->getNextPage(),’class=”pager”‘) ?>
<?php echo link_to(‘Oldest’, ‘news/index?page=’.$pager->getLastPage(),’class=”pager”‘) ?>
<?php } ?></div>

About

me : yeay its me arun

Tagged with: ,
One comment on “Symfony 1.4 Doctrine Pagination
  1. JD says:

    i got this type of error
    Fatal error: __clone method called on non-object in /usr/share/pear/symfony/plugins/sfDoctrinePlugin/lib/pager/sfDoctrinePager.class.php on line 84

1 Pings/Trackbacks for "Symfony 1.4 Doctrine Pagination"

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.