limit and offset

This is primarily used for pagination

Using those additional parameters we need to adjust our where conditions

The adjustments are already introduced here.

Note:

// From
$condition = array('id' => 1);
// To
$condition = array(
    'where' => array(
        'id' => 1
    )
)
// We can also use the other conditions
$condition = array(
    'where' => array(
        'id' => array(
            'in' => array(1,2,3)
        )
    )
)

Usage:

Just add the limit and offset in the root object

$condition = array(
    'where' => array(
        'id' => array(
            'in' => array(1,2,3)
        )
    ),
    'order' => array(
        'id' => 'DESC'
    ),
    'group' => array(
        'id',
        'name'
    ),
    'limit' => 10,
    'offset' => 0
)

$db->news->find($condition);

Last updated