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

Can Resultset be changed? Can I create one Resultset object and add some object into it?

I use $orders =Orders::find () and get one Resultset object: $orders. I loop it like this and I try to update the $order object. $orders->rewind(); while ($orders->valid()) { $order= $orders->current(); echo $order->code, "\n"; $order->code = "xx"; $orders->next(); }

But it didn't take effect. Anyone who can tell me how can I do that? Thanks in advance.



8.1k
edited Mar '14

Because the field properties that are mirror fields of the record data are protected. And you used very hard code, better use foreach

foreach ( $orders as $order ) {
    echo $order->code;
....
}

I found the way to modify instance in Resultset: public function afterFetch() { //Convert the string to an array $this->status = explode(',', $this->status); }

Reference from official document: "You can implement the method ‘afterFetch’ in a model, this event will be executed just after create the instance and assign the data to it:"



8.1k

Of course