Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7514833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:37:05+00:00 2026-05-30T00:37:05+00:00

I have a Coupon controller. The index() function grabs a handful of coupons in

  • 0

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)..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:37:07+00:00Added an answer on May 30, 2026 at 12:37 am

    I think you can do something like this:

    $restaurants = $this->Coupon->findAllBycategory_id('1', '', '', $showPerPage);
    foreach($restaurants['Coupon'] as $restaurant) 
        $couponId[] = $restaurant['id'];
    
    $entertainments = $this->Coupon->findAllBycategory_id('2', '', '', $showPerPage);
    foreach($entertainments['Coupon'] as $entertainment) 
        $couponId[] = $entertainment['id'];    
    
    // ... repeat for all queries
    
    $this->Coupon->updateAll(
        array('Coupon.count' => 'Coupon.count+1'),
        array('Coupon.id' => $couponId)
    );
    
    $this->set(compact('restaurants', 'entertainments'));
    

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my CouponsController.php, I have the following 2 functions: public function index() { $this->set('coupons',
I have the code var expired_overlay=$('.expired-overlay'); expired_overlay.each(function(){ var t=$(this), p=$(this).closest('.coupon'), ph=p.height()+ ((p.css('padding-top').replace(px, ))*2); t.css({'width':p.width(),'height':ph,'opacity':0.5})
I have Image which belongsTo User, and I have Coupon which belongsTo User. Each
I have a link that calls: <a href=/coupons/print_coupon/<?php echo $coupon['id']; } ?> id=print><span style=margin-left:24px;>Print</span></a>
I'm trying to fetch coupons that haven't expired yet. I have this in my
I have the following 3 classes class User { static hasMany = [coupons: Coupon]
I am working with coupon script in php. In this i have to redirect
I'm using CakePHP 2.0. I have 2 models/controllers (Category/Coupon): // File: Model/Coupon.php // Table
I have a coupon code site. On some category pages I'm limiting it to
Please have a look on this application http://itunes.apple.com/app/yowza-mobile-coupons/id312021877?mt=8 I just want to add custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.