You can use https://docs.phalcon.io/en/latest/reference/models.html#using-a-custom-events-manager combined with afterFetch method. Eg:
use Phalcon\Mvc\Model,
Phalcon\Events\Manager as EventsManager;
class Robots extends Model
{
public function initialize()
{
$eventsManager = new EventsManager();
//Attach an anonymous function as a listener for "model" events
$eventsManager->attach('model', function($event, $robot) {
if ($event->getType() == 'afterFetch') {
// Implement your own fetch method here
}
return true;
});
//Attach the events manager to the event
$this->setEventsManager($eventsManager);
}
}
Or if you want the entire resultset object, something like this:
class JsonSimple extends \Phalcon\Mvc\Model\Resultset\Simple implements \JsonSerializable
{
public function jsonSerialize()
{
$arr = array();
foreach ($this as $m) {
$arr[] = $m->toArray();
}
return $arr;
}
}
// Your code ...
use JsonSimple;
class MyModel extends \Phalcon\Mvc\Model
{
public function findSomenthing()
{
$query = "SELECT * FROM table";
return new JsonSimple(null, $o, $o->getReadConnection()->query($query));
}
}