parker
parker

Reputation: 265

Symfony - trying to get all the elements in findBy attribute throws invalid argument supplied for foreach

I have a controller block in my symfony app as shown below where I am using a findBy attribute to get the elements based on the arguments passed to the controller.

This is snippet

$alldata = // all data retrieve

$data = array();
foreach ($alldata as $alldata) { //throws invalid arguments supplied in foreach
    array_push($data, $this->serializeData($alldata));
}

Please how can I get ride of the warning and retrieve all the elements using the findBy attribute.

Upvotes: 1

Views: 59

Answers (1)

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

Change this:

foreach ($alldata as $alldata) {  
    array_push($data, $this->serializeData($alldata));
}

to this:

foreach ($alldata as $all) {
    array_push($data, $this->serializeData($all));
}

The problem is inside the foreach, you need to change the second variable with another name

Upvotes: 1

Related Questions