/**
  * @expectedException \CatLab\CursorPagination\Exceptions\ColumnNotDefinedException
  */
 public function testUnregisteredPropertyException()
 {
     $paginationBuilder = new CursorPaginationBuilder();
     $paginationBuilder->orderBy(new OrderParameter('foobar', OrderParameter::ASC));
     $query = $paginationBuilder->build();
     $paginationBuilder->processResults($query, [['id' => 1, 'foobar' => 2]]);
     $paginationBuilder->getNavigation();
 }
Ejemplo n.º 2
0
// Register properties
$builder->registerPropertyName('id', 'public_id');
$builder->registerPropertyName('name', 'public_name');
$builder->registerPropertyName('score', 'public_score');
/**
 * Set select order
 */
// Order by score desc
$builder->orderBy(new OrderParameter('score', OrderParameter::DESC));
// Same score? Order by name asc
$builder->orderBy(new OrderParameter('name', OrderParameter::ASC));
// Same score and same name? Sort on ID
$builder->orderBy(new OrderParameter('id', OrderParameter::ASC));
// Set the request parameters
$builder->setRequest($_GET);
/**
 * Select and output data
 */
// Build the select query
$query = $builder->build();
// Load the data
$sql = $query->toQuery($pdo, 'entries');
$results = $pdo->query($sql)->fetchAll();
// Post process results. Very important. Don't forget.
$results = $builder->processResults($query, $results);
// Display the records
$table = new Table(['id', 'name', 'score']);
$table->open();
$table->data($results);
$table->close();
$table->navigation($builder->getNavigation());