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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:02:34+00:00 2026-06-16T01:02:34+00:00

I am building a simple mechanism where a user can like a post by

  • 0

I am building a simple mechanism where a user can like a post by clicking on a link. I’m using GET rather than POST as I want to allow the method to fire via the URL.

That been said how do I save data using GET? As the request data doesn’t exist in this scenario… My model looks like:

class Like extends AppModel
{
    public $name = 'Like';

    public $belongsTo = array('User','Post');

}

and the method for adding looks like:

public function add( $id )
{
    $post = $this->Post->find('first', array( 
                'conditions' => array('Post.id'=>Tiny::reverseTiny($id)) 
            ));

    if (!$post)
    {
        throw new NotFoundException('404');
    }

    if($post['Post']['user_id'] == $this->Auth->user('id'))
    {
        $this->Session->setFlash('You can\'t like your own post... That\'s just silly!');
    }

    if ($this->Like->create())
    {
            $liked = $this->Like->find('first', array( 
                'conditions' => array('Like.id'=>Tiny::reverseTiny($id), 'Like.user_id'=>$this->Auth->user('id') ) 
            ));

            if(!$liked){
                $this->Like->saveField('user_id', $this->Auth->user('id'));
                $this->Like->saveField('post_id', $post['Post']['id']);

                $this->redirect(array('controller'=>'posts','action'=>'view','id'=>Tiny::toTiny($post['Post']['id']),'slug'=>$post['Post']['slug']));
            } else {
                $this->Session->setFlash('You already like this post!');
            }
    else
    {
        $this->Session->setFlash('Server broke!');
    }   
}

Can anyone help?

<?php echo $this->Html->link('1', array('controller'=>'followers','action'=>'add','id'=>Tiny::toTiny($post['Post']['id'])),
array('title'=>'Follow','class'=>'follow')); ?>

This part all works fine. It’s saving a new row in the DB on GET that I’m struggling with.

  • 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-16T01:02:35+00:00Added an answer on June 16, 2026 at 1:02 am

    Hi you just need to make a link to your controller action and pass you variable in the url.

    to be clear the link on the post to like is in your post view :
    $this->Html->link(‘like this post’, array(‘controller’ => ‘like’, ‘action’ => ‘add’, $postId))

    It should render a link like this :
    http://www.yourWebSite/likes/add/1 to like the postId 1,

    variables after your action (add) are interpreted as variable for your controller action

    if your fonction add had been

    public function add($postId, $wathever){
    
    }
    

    the url should look like http://www.yourWebSite/likes/add/1/blabla
    where 1 is the first var for the add action and blabla the second one and so on.

    this is the equivalent of a non rewriting url : ?postId=1&whatever=blabla

    EDIT :

    if(!$liked){
                    //simulate the post behaviour
                    $this->request->data['Like']['user_id'] = $this->Auth->user('id');
                    $this->request->data['Like']['post_id'] = $post['Post']['id'];
    
                    //save the data
                    if ($this->Like->save($this->request->data)) {
                        $this->Session->setFlash(__('Thanks for your support !'));
                        $this->redirect(array('controller'=>'posts','action'=>'view','id'=>Tiny::toTiny($post['Post']['id']),'slug'=>$post['Post']['slug']));
                    } else {
                        $this->Session->setFlash('Server broke!');
                    }
    

    }

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

Sidebar

Related Questions

I'm building a simple web application in tornado.web using mongodb as the backend. 90%
I am building a simple particle system and want to use a single array
I'm building a simple search table (eventually using jquery Datatables) for our knowledgebase. I'm
I'm building simple application on as3. Kind of starship game. What I want to
I am building simple blogging framework using PHP and MySQL, and on the add
I building a simple, 7 page, database driven, website, and I would like to
I'm building a simple website generator application in Rails 3.0. I'd like a publish
I am building a simple MVC application in asp.net. I want to follow the
Im building simple family tree application and using Jung to draw the chart. So
building a simple calculator here to get my feet wet with iOS dev. I

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.