We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to ignore the First item of the records result?

$robots = Robots::find();

It can get all the records, but sometimes I want to ignore the first record, How to

I can't do it by SQL limit 1, x, because sometimes the first record can't be ignored

I try to do with array_shift($robots), It says $robots is not an array

can Robots::find() return with array?

edited May '16

Try this

$collection = Robots::find(array(
    'limit' => array('number' => $from, 'offset' => $offset)
));

or use Pagination https://docs.phalcon.io/en/latest/reference/pagination.html#adapters-usage

or use Criteria https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Criteria.html



12.2k
edited May '16

Robots::find() can return as array


Robots::find->toArray();


31.3k

thanks! I think toArray() is a phalcon function that covert an exists object to array....

how to return an array result of the models of phalcon (like php mysql_fetch_array() with array result instead of mysql_fetch_object() with object result)

Robots::find() can return as array


Robots::find->toArray();


31.3k

offset is a solution, thanks! and I'd like to treat it with array.

Try this

$collection = Robots::find(array(
   'limit' => array('number' => $from, 'offset' => $offset)
));

or use Pagination https://docs.phalcon.io/en/latest/reference/pagination.html#adapters-usage

or use Criteria https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Criteria.html



12.2k
Accepted
answer

@xaero7

Here you will find how to return as array by default (by using hydration): https://docs.phalcon.io/en/latest/reference/models.html#hydration-modes



31.3k

That's it! Thanks

@xaero7

Here you will find how to return as array by default (by using hydration): https://docs.phalcon.io/en/latest/reference/models.html#hydration-modes