Guest User

Untitled

a guest
Jan 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2. echo $this->Form->create("Like", array("url" => array("controller" => "likes", "action" => "like")));
  3. echo $this->Form->hidden("user_id",array(
  4. "value" => AuthComponent::user("id")
  5. ));
  6. echo $this->Form->hidden("post_id",array(
  7. "value" => $post["Post"]["id"]
  8. ));
  9. echo $this->Form->end();
  10.  
  11. echo $this->Html->link(
  12. "<li><i class='icon-heart icon-large'></i> ".count($post["Like"])." likes</li>",
  13. "",
  14. array("escape" => false, "onclick" => "document.getElementById('LikeViewForm').submit();")
  15. );
  16. ?>
  17.  
  18. <?php class LikesController extends AppController{
  19.  
  20. function like() {
  21. $user_id = $this->Auth->user("id");
  22. if(!$user_id){
  23. $this->redirect("/");
  24. die();
  25. }
  26. if ($this->request->is("post")) {
  27. $d = $this->request->data;
  28. $d["Like"]["id"] = null;
  29. if($this->Like->save($d,true,array("post_id","user_id"))){
  30. $this->redirect($this->referer());
  31. }
  32. }
  33. }
  34.  
  35. }
  36.  
  37. function like() {
  38. $user_id = $this->Auth->user("id");
  39.  
  40. if (!$user_id) {
  41. $this->redirect("/");
  42. die();
  43. }
  44.  
  45. if ($this->request->is("post")) {
  46. $this->Like->create();
  47. if ($this->Like->save($this->request->data, true, array("post_id", "user_id"))) {
  48. $this->redirect($this->referer());
  49. }
  50. }
  51. }
Add Comment
Please, Sign In to add comment