I've setup my API using Slim PHP. Here's a basic GET request to get all events. I would like to paginate this using Backbone Paginator. My main question is...how do I modify my SELECT statement to accept the parameters from the paginated collection in Backbone? There seems to be nothing out there detailing how you setup your API to receive these requests from the paginator. This post is the closest I could come, but says nothing about what you actually request from the database. Is it just a basic "if this parameter exists, add it to the MySQL statement?" Seems there should be a better way.
$app->get('/events', 'getEvents');
function getEvents() {
// what do I do with the $sort variable?
$sort = $app->request()->params('sort');
$sql = "SELECT * FROM events";
try {
$db = getConnection();
$stmt = $db->query($sql);
$events = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($events);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}