Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function action_like()
- {
- $response = Response::forge();
- $like = Model_Like::forge();
- $like->user_id = Input::post('user_id');
- $like->liked_by = Session::get('sentry_user');
- // find if the user already liked
- $row = Model_Like::find(array($like->user_id, $like->liked_by));
- //if liked remove from database
- if($row):
- $response->body(json_encode(array(
- 'status' => 'no',
- )));
- $row->delete();
- else:
- $response->body(json_encode(array(
- 'status' => 'yes',
- )));
- $like->save();
- endif;
- return $response;
- }
- $('button.like').on('click', function(){
- var likeId = $(this).data('like')
- valPlus = parseInt($('.like-total').text()) + 1;;
- $.ajax({
- type: "POST",
- url: site_url + 'profile/like/',
- data: {user_id: likeId},
- dataType: "json",
- context: this,
- //async: false,
- beforeSend: function(data) {
- $(this).attr('disabled', 'disabled');
- },
- success: function(data) {
- console.debug(data);
- if(data.status == "yes") {
- $('.like-total').text(valPlus);
- }
- },
- complete: function(data) {
- $(this).removeAttr('disabled', 'disabled');
- }
- })
- });
- $row = Model_Like::find()->where(array(
- array('user_id', $like->user_id),
- array('liked_id', $like->liked_by)
- ));
Add Comment
Please, Sign In to add comment