Wednesday, April 17, 2013

Re: changing table fields value for all found in the list

hi david,... 
a quick question,... 

do I have to have "&" upfront of $photo
 in foreach ($photos as &$photo) 
and what is it stand for..? 

thanks 
chris 



On Monday, April 15, 2013 11:17:31 PM UTC-7, david...@gmail.com wrote:
You are doing a redirect inside of your loop which is kicking you out of your loop.  That is why only the first update works.

Also, there is no need to use the query method.  You would be better off looping through the returned items and setting the privacy field and then calling saveAll
i.e.
foreach ($photos as &$photo)
{
  $photo['Photo']['privacy'] = 2;
}
$this->Photo->saveAll($photos);

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: