CakePHP:保持“视图”数数
我有一个“优惠券”控制器。 index() 函数抓取每个类别中的一些优惠券并显示它们(即):
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));
}
对于每个数组集(餐厅、娱乐场所、水疗中心等),我想过滤每个优惠券并增加他们的“mini_views”与 1 相反。我在模型中创建了一个名为“increaseMiniView($id)”的函数。处理这个问题的最佳方法是什么?我知道我可以遍历每个,但我不知道是否有更好的方法(我也可以将代码放在视图中,但我知道这也是最好的方法)。
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)..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以这样做:
复杂查找条件和更新全部。
将所有优惠券 ID 存储在一个数组中,并将它们传递给 updateAll 方法,您可以在其中更新您想要的任何字段。
祝你好运!
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!