Abstract class Phalcon\Mvc\Model\Resultset

implements Phalcon\Mvc\Model\ResultsetInterface, Iterator, Traversable, SeekableIterator, Countable, ArrayAccess, Serializable, JsonSerializable

Source on GitHub

This component allows to Phalcon\Mvc\Model returns large resultsets with the minimum memory consumption Resultsets can be traversed using a standard foreach or a while statement. If a resultset is serialized it will dump all the rows into a big array. Then unserialize will retrieve the rows as they were before serializing.

  1. <?php
  2. // Using a standard foreach
  3. $robots = Robots::find(
  4. [
  5. "type = 'virtual'",
  6. "order" => "name",
  7. ]
  8. );
  9. foreach ($robots as robot) {
  10. echo robot->name, "\n";
  11. }
  12. // Using a while
  13. $robots = Robots::find(
  14. [
  15. "type = 'virtual'",
  16. "order" => "name",
  17. ]
  18. );
  19. $robots->rewind();
  20. while ($robots->valid()) {
  21. $robot = $robots->current();
  22. echo $robot->name, "\n";
  23. $robots->next();
  24. }

Constants

integer TYPE_RESULT_FULL

integer TYPE_RESULT_PARTIAL

integer HYDRATE_RECORDS

integer HYDRATE_OBJECTS

integer HYDRATE_ARRAYS

Methods

public __construct (Phalcon\Db\ResultInterface | false $result, [Phalcon\Cache\BackendInterface $cache])

Phalcon\Mvc\Model\Resultset constructor

public next ()

Moves cursor to next row in the resultset

public valid ()

Check whether internal resource has rows to fetch

public key ()

Gets pointer number of active row in the resultset

final public rewind ()

Rewinds resultset to its beginning

final public seek (mixed $position)

Changes internal pointer to a specific position in the resultset Set new position if required and set this->_row

final public count ()

Counts how many rows are in the resultset

public offsetExists (mixed $index)

Checks whether offset exists in the resultset

public offsetGet (mixed $index)

Gets row in a specific position of the resultset

public offsetSet (int $index, Phalcon\Mvc\ModelInterface $value)

Resultsets cannot be changed. It has only been implemented to meet the definition of the ArrayAccess interface

public offsetUnset (mixed $offset)

Resultsets cannot be changed. It has only been implemented to meet the definition of the ArrayAccess interface

public getType ()

Returns the internal type of data retrieval that the resultset is using

public getFirst ()

Get first row in the resultset

public getLast ()

Get last row in the resultset

public setIsFresh (mixed $isFresh)

Set if the resultset is fresh or an old one cached

public isFresh ()

Tell if the resultset if fresh or an old one cached

public setHydrateMode (mixed $hydrateMode)

Sets the hydration mode in the resultset

public getHydrateMode ()

Returns the current hydration mode

public getCache ()

Returns the associated cache for the resultset

public getMessages ()

Returns the error messages produced by a batch operation

public boolean update (array $data, [Closure $conditionCallback])

Updates every record in the resultset

public delete ([Closure $conditionCallback])

Deletes every record in the resultset

public Phalcon\Mvc\Model[] filter (callback $filter)

Filters a resultset returning only those the developer requires

  1. <?php
  2. $filtered = $robots->filter(
  3. function ($robot) {
  4. if ($robot->id < 3) {
  5. return $robot;
  6. }
  7. }
  8. );

public array jsonSerialize ()

Returns serialised model objects as array for json_encode. Calls jsonSerialize on each object if present

  1. <?php
  2. $robots = Robots::find();
  3. echo json_encode($robots);

abstract public toArray () inherited from Phalcon\Mvc\Model\ResultsetInterface

abstract public current () inherited from Iterator

abstract public serialize () inherited from Serializable

abstract public unserialize (mixed $serialized) inherited from Serializable