XF 2.0 Fetch entities WITHOUT keying?

Jaxel

Well-known member
By default, when you use the entity finder system, it keys each object to the primary_key of the entity. This is great, normally...

But for my purpose, I want to know the position # of the object in the array. So I'm looking to fetch the entities with array keys starting from 0 and counting up.

How could I get this done?
 
Kind of a dirty way to do it, but it works...
Code:
$objects = $finder('Whatever:Table')->fetch();
$array = $objects->toArray();
$renumberedArray = array_values($array);
The result will be an array ordered 0 to ~ and accessible by $renumberedArray[0], $renumberedArray[1], etc..

However, it requires fetching the entire table or a known number of records to get position. Other than that, there's no way to do what you want that I know of.

Note that fetch() accepts a limit and offset, so that might be useful to you too.
 
Last edited:
Back
Top Bottom