Вопрос

I'm using the paginate method from the DB Cursor Class of Fat Free Framework, but looking at the code there is something I cannot get my head around.

$mapper->paginate([ int $pos = 0 ], [ int $size = 10 ], [ string|array $filter = NULL ], [ array $options = NULL ]);

It looks like the $pos parameter is supposed to be the offset in the query result and the $size parameter is the length requested for the results. Am I right?

Here comes my question...

Why in the code at line 89 of fatfreeframework/db/cursor.php is offset defined as $pos * $size?

If I call $mapper->paginate( 52, 10 ) I'd like to see 10 records starting from the 52nd and NOT 10 records starting from the 520th!

Am I missing something?

Should I use the $pos parameter like it were a page number?

Thank you

Это было полезно?

Решение

Yes the $pos var is meant to be the page number offset. If you set it to 52, you'll get the 52th page, based on your page size (Limit), like the name paginate suggests. If you simply want to use an offset and limit in your query, you can use something like $mapper->find(array('foo > 1'),array('limit'=>10,'offset'=>520)); which would be the equivalent to paginate page no. 52

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top