This quick tutorial explain how it’s simple to set pagination on module view using symfony
In apps/myapp/modules/mymodule/actions/actions.class.php insert:
<pre>public function executeIndex(sfWebRequest $request)
{
$this->pager = new sfDoctrinePager('TableName', '5');
$this->pager->setQuery(Doctrine::getTable('TableName')->createQuery('a'));
//set first page as default (get parameter page)
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
}
In apps/myapp/modules/mymodule/templates/indexSuccess.php<?php foreach ($pager->getResults() as $customer): ?> <tr> <td><?php echo $customer->getId() ?></td> <td><?php echo $customer->getName() ?></td> <td><?php echo $customer->getSurname() ?></td> </tr> <?php endforeach; ?> <?php // check if results > 5 ?> <?php if ($pager->haveToPaginate()): ?> <ul id="pagination"> <?php $links = $pager->getLinks(); foreach ($links as $page): ?> <li> <?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'mymodule/index?page='.$page) ?> </li> <?php endforeach ?> </ul> <?php endif ?>You can also use this two strings to get first and last elements of your pagination:
<?php //for the first page ?> <?php echo link_to('first', 'module/index?page='.$pager->getFirstPage()) ?><?php //for the last page ?> <?php echo link_to('last', 'module/index?page='.$pager->getLastPage()) ?>
This quick tutorial explain how it’s simple to set pagination on module view using symfony
In apps/myapp/modules/mymodule/actions/actions.class.php insert:
<pre>public function executeIndex(sfWebRequest $request)
{
$this->pager = new sfDoctrinePager('TableName', '5');
$this->pager->setQuery(Doctrine::getTable('TableName')->createQuery('a'));
//set first page as default (get parameter page)
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
}
In apps/myapp/modules/mymodule/templates/indexSuccess.php<?php foreach ($pager->getResults() as $customer): ?> <tr> <td><?php echo $customer->getId() ?></td> <td><?php echo $customer->getName() ?></td> <td><?php echo $customer->getSurname() ?></td> </tr> <?php endforeach; ?> <?php // check if results > 5 ?> <?php if ($pager->haveToPaginate()): ?> <ul id="pagination"> <?php $links = $pager->getLinks(); foreach ($links as $page): ?> <li> <?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'mymodule/index?page='.$page) ?> </li> <?php endforeach ?> </ul> <?php endif ?>You can also use this two strings to get first and last elements of your pagination:
<?php //for the first page ?> <?php echo link_to('first', 'module/index?page='.$pager->getFirstPage()) ?><?php //for the last page ?> <?php echo link_to('last', 'module/index?page='.$pager->getLastPage()) ?>
Commenti