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

how to change a value of $page object in loop

…… ……

$page = $paginator->getPaginate();

foreach($page->items as &$item) { $item->value = 0; }

how to change a object value in the loop, the code above can not work.

you can try

$page = $paginator->getPaginate();

foreach($page->items as &$item) { $item = 0; }

or with for

for(i=o;i>=$page.lenght;i++) { $page[i] = 0; }



1.7k

you can try

$page = $paginator->getPaginate();

foreach($page->items as &$item) { $item = 0; }

or with for

for(i=o;i>=$page.lenght;i++) { $page[i] = 0; }

when I do this , It appears : Fatal error: An iterator cannot be used with foreach by reference in C:\xampp\htdocs\dict\app.....

In $page->items is array of models. So you can do somethink like this:

$newItems = array();
foreach ($page->items as $item) {
  $item->value = 0;
  $newItems[] = $item;
}

$page->items = $newItems;