I create simple for loop:
// controller:
$properties = Properties::find(['order' => 'sort_id']);
$this->view->setVar('properties', $properties);
//view:
{% for property in properties %}
1st loop index - {{ loop.index }}
{% endfor %}
//output:
1st loop index - 1
1st loop index - 2
That's ok. Than I added nested loop:
//view:
{% for property in properties %}
1st loop index - {{ loop.index }}
{% for _property in properties %}
2st loop index - {{ loop.index }}
{% endfor %}
{% endfor %}
//output:
1st loop index - 1
2st loop index - 1
2st loop index - 2
1st loop was executed only 1 time. What I'm doing wrong?
This dosen't work in controller too:
$properties = Properties::find(['order' => 'sort_id']);
foreach ($properties as $property) {
echo '1st ' . $property->id . PHP_EOL;
foreach ($properties as $p) {
echo '2nd ' . $p->id . PHP_EOL;
}
}
//output:
1st 4
2nd 4
2nd 3
Fix:
foreach ($properties as $property) {
$key = $properties->key();
echo '1st ' . $property->id . PHP_EOL;
foreach ($properties as $p) {
echo '2nd ' . $p->id . PHP_EOL;
}
$properties->seek($key);
}
//output:
1st 4
2nd 4
2nd 3
1st 3
2nd 4
2nd 3
I think it's a bug in Phalcon\Mvc\Model\Resultset\Simple, no?