I have a “Coupon” controller. The index() function grabs a handful of coupons in each category and display them (ie):
public function index() {
$showPerPage = 4;
$this->Coupon->recursive = 0;
$this->set('restaurants', $this->Coupon->findAllBycategory_id('1', '', '', $showPerPage));
$this->set('entertainment', $this->Coupon->findAllBycategory_id('2', '', '', $showPerPage));
$this->set('spas', $this->Coupon->findAllBycategory_id('3', '', '', $showPerPage));
$this->set('services', $this->Coupon->findAllBycategory_id('4', '', '', $showPerPage));
$this->set('hotels', $this->Coupon->findAllBycategory_id('5', '', '', $showPerPage));
$this->set('retail', $this->Coupon->findAllBycategory_id('6', '', '', $showPerPage));
}
For each array set (restaurants, entertinamnent, spas, etc), I want to filter through each coupon and increase their “mini_views” counter to 1. I’ve created a function in the model called “increaseMiniView($id)”. What’s the best way to handle this? I know I can just foreach through each one, but I didn’t know if there was a better way (I could also place the code in the view, but I know that’s the best way either)..
I think you can do something like this:
Complex Find Conditions and updateAll.
Store all coupon id’s in an array and pass them trough to the updateAll method in which you could update any field you want.
Good luck!