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

  • Home
  • SEARCH
  • 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 3424524
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:29:04+00:00 2026-05-18T06:29:04+00:00

I have an Article controller & model. I want to have a function that

  • 0

I have an Article controller & model. I want to have a function that adds one to an integer when a link is clicked. So I have say a “i like” button (link) it takes me to Articles/thumbsup it will then take the thumbsup field of that article and increment it by one, then save the article, and redirect to the view.

I’m not sure how to modify records in this way. I need to load the article, modify the data and then save it.

My hope is that this be handled by javascript so noone will see the url change.

Can someone help me out here?

Thanks,

Jonesy

Thanks,

Billy

  • 1 1 Answer
  • 3 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-18T06:29:05+00:00Added an answer on May 18, 2026 at 6:29 am

    You can do that with an AjaxRequest.

    models/article.php:

    function thumbsup($id = null)
      {
      $conditions = array('Article.id' => $id);
      $this->updateAll(
        array('Article.thumbsup' => 'Article.thumbsup + 1'),
        $conditions
        );
      $article = $this->find(
        'first',
        array('conditions' => $conditions, 'fields' => array('Article.thumbsup'))
        );
      return $article['Article']['thumbsup'];
      }
    

    controllers/articles_controller.php:

    function thumbsup($id = null)
      {
      $this->set('count', $this->Article->thumbsup($id));
      $this->layout = 'ajax';
      }
    

    views/articles/thumbsup.ctp:

    <?php echo $count; ?>
    

    webroot/js/thumbsup.js:

    $(document).ready(function()
      {
      $('.iLikeSomething').click(function()
        {
        $.post('http://yoursite.com/articles/incrementThumbsup/'+this.id, function(data)
          {
          $('#iLikeSomethingCount').html(data);
          });
        });
      });
    

    Html sample for clicking:

    <span class="iLikeSomething" id="insertYourArticleIdHere" style="cursor: pointer;">iLike</span>
    <div id="iLikeSomethingCount">0</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an article controller that deals with articles. I have a comment model
When I have a controller, e.g. article I often have a action_view() that handles
I have model Article it has field title with some text that may contain
Say that I have an article with multiple pages. Each page has a short
I Have Make a Create Form. & I want the Values in Controller how
Say I have an Article model, and in the article 'new' view I have
I have an article controller, which manages all article relations like authors, translations, related
This is the code that I have in my controller: [HttpPost] public ActionResult UpdateArticle(Article
I have a controller called articles , which creates the articles model which gets
In my app I have a article and comment model. I implemented a reply-feature,

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.