Skip to content

Instantly share code, notes, and snippets.

@cornernote
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cornernote/77377be621e67dde0511 to your computer and use it in GitHub Desktop.
Save cornernote/77377be621e67dde0511 to your computer and use it in GitHub Desktop.
But Like
<?php
class PostsController extends Controller
{
public function actionLike($id)
{
$model = $this->loadModel($id);
$model->views = $model->views + 1;
$model->save();
echo $model->views;
}
}
<?php
echo CHtml::ajaxLink(
$text = 'Like',
$url = $this->createUrl('posts/like', array('id' => $model->id)),
$ajaxOptions=array (
'type'=>'POST',
'dataType'=>'json',
'success'=>'function(count){ jQuery("#like-count").html(count); }',
),
$htmlOptions=array ()
);
echo '<div id="like-count"></div>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment