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 8693873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:38:40+00:00 2026-06-13T00:38:40+00:00

Every time a user views a submission, I track the count and tie it

  • 0

Every time a user views a submission, I track the count and tie it to a session:

SubmissionsController:

// Count view
if ($this->Session->check('viewed_submission_' . $submissionId) !== true) {
    $clientIp = ip2long($this->request->clientIp());
    $this->SubmissionsViews->countView($submissionId, $clientIp);
    $this->Session->write('viewed_submission_' . $submissionId, true);
}

I’m keeping track of them in a SubmissionsViews table.

SubmissionsViews Model:

class SubmissionsViews extends AppModel {

    var $name = 'SubmissionsViews';

    var $belongsTo = array(
        'Submission' => array(
            'className' => 'Submission'
        )   
    );

    public function countView($submissionId, $clientIp) {
        $this->set('submission_id', $submissionId);
        $this->set('user_ip', $clientIp);
        $this->save($this->data);
    }   
}

My SubmissionsView table submissions_views has the following fields:

  • id
  • submission_id
  • user_ip
  • created

I’m trying to set up counterCache to keep track of additions to that table, but not sure how to set it up. I’m currently adding the counterCache in my $belongsTo within my Submission model:

class Submission extends AppModel {
    var $belongsTo = array(
        'User' => array(
            'className' => 'User'
        ),
        'SubmissionsViews' => array(
            'counterCache' => true
        )   
    ); 

But it’s telling me it can’t find Submission.submissions_views_id. In the documentation, all it said was that I needed to add a field to my submissions table called submissions_views_count, so I’m confused how to get this working?

  • 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-06-13T00:38:42+00:00Added an answer on June 13, 2026 at 12:38 am
    1. Model names should be singlular, so SubmissionViews should be SubmissionView.
    2. Your association is incorrect. Submission hasMany SubmissionView, not belongsTo.
    3. counterCache needs to be specified in the SubmissionView model inside the belongsTo config for Submission, not in the Submission model file. Please read the manual more carefully.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every time a user clicks on a link in a list view unordered list,
I have a list view contains 100+ rows. every time the user opens the
In my app, every time a user switches to a new view a sound
The JavaScript code below is executed every time the user selects the login button
I need to start a program every time the user logs in, but I
I want to refresh a table using a SSIS package every time the user
I have a photo gallery I would like that every time a user does
I want to do input validation with jQuery. Every time the user blurs an
I have a MYSQL-Table which stores scores. Every time a user improves a new
I'm writing a Word/VBA macro for a document template. Every time a user saves/creates

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.