I have an array with data, all with their own unique ID. I'm using the ORM method find('all') and the resulting array looks somewhat like this:
Array
(
[0] => Array
(
[Wijken] => Array
(
[id] => 1
[name] => Naam
[lat] => 13.37
[lon] => 13.37
[zoom] => 14
)
)
)
From my Routing I'm receiving an unique ID.. What I want, is re-use my array and get the data from, let's say, ID 1.
So what I need is that the indexes of my associative array (returned by find('')) are being set with the id of the "Wijken"-object itself.
I explained everything, just in case people have a different approach. Querying the database again with the param ID is not acceptable though.
try Set::combine
To maintain find('all') structure (from icc97 comment):
$idsAsIndexes = Set::combine($wijkens, '{n}.Wijken.id', '{n}');
Alternatively you can also extract a single model:
$idsAsIndexes = Set::combine($wijkens, '{n}.Wijken.id', '{n}.Wijken');
hope that's what you are looking for :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With