Last active
August 29, 2015 14:11
-
-
Save cornernote/77377be621e67dde0511 to your computer and use it in GitHub Desktop.
But Like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PostsController extends Controller | |
{ | |
public function actionLike($id) | |
{ | |
$model = $this->loadModel($id); | |
$model->views = $model->views + 1; | |
$model->save(); | |
echo $model->views; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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