Question

I was introduced to the PHP Fat Free Framework yesterday and I am now exploring its possibilities for my REST api. I am now trying to do a select query with limit and offset parameters. Following its documentation, I came up with the following:

$query = array('userid=?', F3::get('userid'));
$extra = array(
    'order'     =>'id DESC',
    'offset'    => isset($_GET['offset']) ? (int)$_GET['offset'] : 0,
    'limit'     => isset($_GET['limit']) ? (int)$_GET['limit'] : 5
);
$list = $this->mapper->find($query, $extra);

However, while I was under the impression that F3 would handle the escaping, it doesn't. Am I using the framework in the wrong way, or how should I handle the escaping here?

Was it helpful?

Solution

Instead of using find() you should use paginate() like this:

$list = $this->mapper->paginate(2, 5, array('userid=?', F3::get('userid')));

Check out the docs, it's quite easy to use. The result is different than find(), though, since it contains more info. The items returned will be in $list['subset']. You can do a var_dump of $list to see the other fields returned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top