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.



7.0k
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:"



7.0k

Of course