Beispiel #1
0
 function listing($locator)
 {
     $usersession = $locator->get('UserSession');
     $db = $locator->get('Db');
     $template = $this->_load('controller')->template('listing');
     // create a data object that has the interface needed by the Pager object
     $datasource = new A_Pagination_Adapter_Db($db, "SELECT * FROM `blog_posts` WHERE post_type='post'");
     // create a request processor to set pager from GET parameters
     $pager = new A_Pagination_Request($datasource);
     // initialize using values from $_GET
     $pager->process($locator->get('Request'));
     // create a "standard" view object to create pagination links
     $view = new A_Pagination_View_Standard($pager);
     $rows = $pager->getItems();
     $template->set('rows', $rows);
     $template->set('links', $view->render());
     // display the pagination links
     $this->response->set('maincontent', $template->render());
 }
<head>
<title>Skeleton - Pagination example - basic</title>
</head>
<body>
<?php 
include 'config.php';
include dirname(__FILE__) . '/../../A/autoload.php';
// initialize an array for testing
for ($i = 0; $i <= 750; ++$i) {
    $myarray[$i]['title'] = 'This is row ' . $i;
    $myarray[$i]['month'] = date('F', time() + $i * 60 * 60 * 24 * 30);
}
// create a data object that has the interface needed by the Pager object
$datasource = new Datasource($myarray);
// create a request processor to set pager from GET parameters
$pager = new A_Pagination_Request($datasource);
$pager->setRangeSize(3)->process();
#include 'A/Pagination/View/Standard.php';
$view1 = new A_Pagination_View_Standard($pager);
$view2 = new A_Pagination_View_Standard($pager);
$view2->alwaysShowFirstLast();
$view3 = new A_Pagination_View_Standard($pager);
$view3->alwaysShowPreviousNext();
$view4 = new A_Pagination_View_Standard($pager, false, true);
$view4->alwaysShowFirstLast();
$view4->alwaysShowPreviousNext();
?>

<h3>Standard</h3>
<pre>$view = new A_Pagination_View_Standard($pager);</pre>
<div><?php 
<title>Skeleton - Pagination example - basic</title>
</head>
<body>
<?php 
include 'config.php';
include dirname(__FILE__) . '/../../A/autoload.php';
// initialize an array for testing
for ($i = 0; $i <= 750; ++$i) {
    $myarray[$i]['title'] = 'This is row ' . $i;
    $myarray[$i]['month'] = date('F', time() + $i * 60 * 60 * 24 * 30);
}
#$myarray = null;
// create a data object that has the interface needed by the Pager object
$datasource = new Datasource($myarray);
// create a request processor to set pager from GET parameters
$pager = new A_Pagination_Request($datasource);
// set range (number of links on either side of current page) and process core based on request
$pager->setRangeSize(3)->process();
// create a new link helper
$link = new A_Pagination_Helper_Link($pager);
// create a new order link helper
$order = new A_Pagination_Helper_Order($pager, $url, array('' => 'Row', 'title' => 'Title', 'month' => 'Month'));
// retrieve items on current page
$rows = $pager->getItems();
// display the paging links ... should this go in a template?
$links = '';
$links .= $link->first('First');
$links .= $link->previous('Previous');
$links .= $link->range();
$links .= $link->next('Next');
$links .= $link->last('Last');
<html>
<head>
<title>Skeleton - Pagination example - Standard Request</title>
</head>
<body>
<?php 
include 'config.php';
include dirname(__FILE__) . '/../../A/autoload.php';
// create a data object that has the interface needed by the Pager object
$datasource = new A_Pagination_Adapter_File('constitution.txt');
// create a request processor to set pager from GET parameters
$pager = new A_Pagination_Request($datasource);
// set core values based on request
$pager->process();
// create a new standard view
$view = new A_Pagination_View_Standard($pager);
// retrieve items on current page
$rows = $pager->getItems();
// Set up view internally. For first/last, label is optional. If no label is passed, the number will be displayed.
$view->first('First')->previous('Previous')->range()->next('Next')->last('Last');
// display the data
echo "<div>{$view->render()}</div>";
echo '<table border="1">';
$n = 1;
foreach ($rows as $value) {
    echo '<tr>';
    echo '<td>' . $n++ . '.</td><td>' . $value['line'] . '</td>';
    echo '</tr>';
}
echo '</table>';
echo "<div>{$view->render()}</div>";
<body>
<?php 
include 'config.php';
include dirname(__FILE__) . '/../../A/autoload.php';
// initialize an array for testing
for ($i = 0; $i <= 750; ++$i) {
    $myarray[$i]['title'] = 'This is row ' . $i;
    $myarray[$i]['month'] = date('F', time() + $i * 60 * 60 * 24 * 30);
}
#$myarray = null;
// create a data object that has the interface needed by the Pager object
$datasource = new Datasource($myarray);
// use a request object
$request = new A_Http_Request();
// create a request processor to set pager from GET parameters
$pager = new A_Pagination_Request($datasource);
$pager->setRangeSize(3)->process($request);
$url = new A_Pagination_Helper_Url();
$url->set('page', $pager->getCurrentPage());
$url->set('order_by', $pager->getOrderBy());
$rows = $pager->getItems();
// display the paging links ... should this goes in a template?
$links = array();
if ($pager->isPage(-1)) {
    $links[] = "<a href=\"" . $url->render(false, array('page' => $pager->getPage(-1))) . "\">Previous</a>";
}
if (!$pager->inPageRange($pager->getFirstPage())) {
    $links[] = "<a href=\"" . $url->render(false, array('page' => $pager->getFirstPage())) . "\">1</a> ... ";
}
//if ($pager->isIntervalPage(-10)) $links[] = "<a href=\"" . $url->render(false, array ('page' => $pager->getPage(-10))) . "\">" . $pager->getPage(-10) . "</a> ...";
foreach ($pager->getPageRange() as $page) {
<head>
<title>Skeleton - Pagination example - Standard Request</title>
</head>
<body>
<?php 
include 'config.php';
include dirname(__FILE__) . '/../../A/autoload.php';
// initialize an array for testing
for ($i = 0; $i <= 750; ++$i) {
    $myarray[$i]['title'] = 'This is row ' . $i;
    $myarray[$i]['month'] = date('F', time() + $i * 60 * 60 * 24 * 30);
}
// create a data object that has the interface needed by the Pager object
$datasource = new Datasource($myarray);
// create a request processor to set pager from GET parameters
$pager = new A_Pagination_Request($datasource);
$pager->setParamNamespace('green_');
// set range (number of links on either side of current page) and process core based on request
$pager->setRangeSize(3)->process();
// create a new standard view
$view = new A_Pagination_View_Standard($pager);
// retrieve items on current page
$rows = $pager->getItems();
// Set up view internally. For first/last, label is optional. If no label is passed, the number will be displayed.
$view->first('First')->previous('Previous')->range()->next('Next')->last('Last');
// display the data
echo "<div>{$view->render()}</div>";
echo '<table border="1">';
echo '<tr><th>' . $view->link()->order('', 'Row') . '</th><th>' . $view->link()->order('title', 'Title') . '</th><th>' . $view->link()->order('month', 'Month') . '</th></tr>';
$n = 1;
foreach ($rows as $value) {