This is an example describing how a module can implement a pager in order
to reduce the number of output rows to the screen and allow a user
to scroll through multiple screens of output.
See:
Database API
Extenders
File
modules/examples/pager_example/pager_example.module
View source <?php
* @file
* This is an example describing how a module can implement a pager in order
* to reduce the number of output rows to the screen and allow a user
* to scroll through multiple screens of output.
*
* See:
* @link http://DOCUMENTATION_PENDING/developing/api/database Database API @endlink
* @link http://DOCUMENTATION_PENDING Extenders @endlink
*/
* @defgroup pager_example Example: Pager
* @ingroup examples
* @{
* Example of a results pager.
*/
* Implements hook_menu().
*/
function pager_example_menu () {
$items ['examples/pager_example' ] = array (
'title' => 'Pager example' ,
'description' => 'Show a page with a long list across multiple pages' ,
'page callback' => 'pager_example_page ' ,
'access callback' => TRUE ,
);
return $items ;
}
* Build the pager query.
*
* Uses the menu_links table since it is installed with several rows
* in it and we don't have to create fake data in order to show
* this example.
*
* @return array
* A render array completely set up with a pager.
*/
function pager_example_page () {
$header = array (
array ('data' => t ('MLID' )),
array ('data' => t ('Link title' )),
array ('data' => t ('Menu name' )),
);
$query = db_select ('menu_links' , 'm' )->extend ('PagerDefault' );
$query ->fields ('m' , array ('mlid' , 'link_title' , 'menu_name' ));
$result = $query
->condition ('m.link_title' , '' , '<>' )
->limit (10 )
->orderBy ('m.mlid' )
->execute ();
$rows = array ();
foreach ($result as $row ) {
$rows [] = array ('data' => (array) $row );
}
$build ['pager_table' ] = array (
'#theme' => 'table ' ,
'#header' => $header ,
'#rows' => $rows ,
'#empty' => t ('There are no date formats found in the db' ),
);
$build ['pager_pager' ] = array ('#theme' => 'pager ' );
return $build ;
}
* @} End of "defgroup pager_example".
*/
Functions