I have an action with this code:
$c = new Criteria();
$c->addJoin(sfGuardUserProfilePeer::USER_ID, sfGuardUserGroupPeer::USER_ID, Criteria::INNER_JOIN);
$c->add(sfGuardUserGroupPeer::GROUP_ID, 2 );
$this->pager = new PropelPager($c, 'sfGuardUserProfilePeer', 'doSelect', $page = 2, $rowsPerPage = 1);
And in the corresponding template this:
<table>
<?php foreach ($pager->getResult() as $book): ?>
<tr>
<td><?php echo $book->getName() ?></td>
<td><?php echo $book->getSurname() ?></td>
</tr>
<?php endforeach; ?>
</table>
When i call the action I get the first page with the first results, but what is the URL for the page 2 ?
Thanks!
sf 1.4/pr 1.5
Javi
Firstly, you have to correct your code:
$this->pager = new PropelPager($c, 'sfGuardUserProfilePeer', 'doSelect', $page, $rowsPerPage);
Secondly, only you define how page number is handled in your action. I'd prefer page
parameter in URL:
// $request - a sfWebRequest object passed to your action
$page = $request->getParameter('page', 1); // first page by default
$this->pager = new PropelPager($c, 'sfGuardUserProfilePeer', 'doSelect', $page = 2, $rowsPerPage = 1);
And then you have to manully generate links to pages in your view:
<table>
<?php if ($pager->getNbResults()): ?>
<?php foreach ($pager->getResults() as $book): ?>
<tr>
<td><?php echo $book->getName() ?></td>
<td><?php echo $book->getSurname() ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<?php if ($pager->haveToPaginate()): ?>
display pagination here and generate "uri/?page=N" links
<?php endif; ?>
So, all available pages are retrieved by $pager->getLinks()
. Result is array.
Further reading:
Hope that helps.