N
N
Nikolai Gromov2017-04-28 10:00:45
Zend Framework
Nikolai Gromov, 2017-04-28 10:00:45

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

1 answer(s)
S
Shirshov Alexander, 2017-05-22
@Keanor

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 question

Ask a Question

731 491 924 answers to any question