Answer the question
In order to leave comments, you need to log in
How to pull an object out of a loop?
Hello.
I have a loop and I need to get the value of the $queries variable out of it, without changing it. Because this variable contains the paginator object and it should not be subject to any changes.
$categoryId = $this->params()->fromRoute('id', -1);
$cat = $this->entityManager->getRepository(Category::class)
->ChildrenCategory($categoryId);
if ($cat == null) {
$this->getResponse()->setStatusCode(404);
return;
} else {
foreach ($cat as $c){
$queries = $this->entityManager->getRepository(Products::class)
->getProductsById($c->getId());
}
}
Answer the question
In order to leave comments, you need to log in
Speak humanly what you need.
Do you need to change the scope of the $queries variable? Above the loop add $queries = null;
In this form, after the array is iterated, the reference to the last result will remain in the variable.
If you need a "paginator object" for all categories, then this is not at all the case.
If you need a "paginator object" for one category, then look for one and not all children
. An object that the paginator understands, not a Doctrine CollectionInterface by any chance?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question