Re: array of objects in the controller
OK, this has nothing to do with differences between views and controllers, this is basic PHP logic. The error message is telling you what you need to know, so try and figure out why $existingUsers is not a valid argument to be passed to foreach(). Hint: it's not an array or it's empty. HTH Paul. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: array of objects in the controller
Thanks for your answer The problem in I dont want to send the result to the view, i need to do some process in the contorller. something like : $existingUsers = $this->userSubscriptions(24); foreach($existingUsers as $existingUser): $m = $m .$existingUser['UsersCity']['id']; endforeach; But im getting this erro: Warning (2): Invalid argument supplied for foreach() [APP\controllers\users_cities_controller.php, line 172] really dont know how to solve it!!! calvin-38 wrote: > > What exactly is the problem? If you know how to do that in the view, > then you can do the same thing in the controller. There's nothing > magical about passing find() results to the view using $this->set(). > All it does is "set" the variables you specify in the view. If you > don't know the structure of $coupons, just use debug() to view it. > > Also, technically those aren't objects, otherwise you'd access the > 'title' property by $coupon->title; they're just associative arrays. > > On May 26, 10:48 am, sherzo wrote: >> Hi all >> >> I need to have something like the following code but in the controller >> not >> view. >> foreach ($coupons as $coupon) >> $st = $coupon['Coupon']['title']; >> endforeach; >> >> and the $coupons is the result of a find() function. >> >> any idea? >> >> Thanks >> Sherrt >> -- >> View this message in >> context:http://old.nabble.com/array-of-objects-in-the-controller-tp28684091p2... >> Sent from the CakePHP mailing list archive at Nabble.com. > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group > at http://groups.google.com/group/cake-php?hl=en > > -- View this message in context: http://old.nabble.com/array-of-objects-in-the-controller-tp28684091p28684491.html Sent from the CakePHP mailing list archive at Nabble.com. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: array of objects in the controller
What exactly is the problem? If you know how to do that in the view, then you can do the same thing in the controller. There's nothing magical about passing find() results to the view using $this->set(). All it does is "set" the variables you specify in the view. If you don't know the structure of $coupons, just use debug() to view it. Also, technically those aren't objects, otherwise you'd access the 'title' property by $coupon->title; they're just associative arrays. On May 26, 10:48 am, sherzo wrote: > Hi all > > I need to have something like the following code but in the controller not > view. > foreach ($coupons as $coupon) > $st = $coupon['Coupon']['title']; > endforeach; > > and the $coupons is the result of a find() function. > > any idea? > > Thanks > Sherrt > -- > View this message in > context:http://old.nabble.com/array-of-objects-in-the-controller-tp28684091p2... > Sent from the CakePHP mailing list archive at Nabble.com. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
array of objects in the controller
Hi all I need to have something like the following code but in the controller not view. foreach ($coupons as $coupon) $st = $coupon['Coupon']['title']; endforeach; and the $coupons is the result of a find() function. any idea? Thanks Sherrt -- View this message in context: http://old.nabble.com/array-of-objects-in-the-controller-tp28684091p28684091.html Sent from the CakePHP mailing list archive at Nabble.com. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en