Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo $this->Form->create("Like", array("url" => array("controller" => "likes", "action" => "like")));
- echo $this->Form->hidden("user_id",array(
- "value" => AuthComponent::user("id")
- ));
- echo $this->Form->hidden("post_id",array(
- "value" => $post["Post"]["id"]
- ));
- echo $this->Form->end();
- echo $this->Html->link(
- "<li><i class='icon-heart icon-large'></i> ".count($post["Like"])." likes</li>",
- "",
- array("escape" => false, "onclick" => "document.getElementById('LikeViewForm').submit();")
- );
- ?>
- <?php class LikesController extends AppController{
- function like() {
- $user_id = $this->Auth->user("id");
- if(!$user_id){
- $this->redirect("/");
- die();
- }
- if ($this->request->is("post")) {
- $d = $this->request->data;
- $d["Like"]["id"] = null;
- if($this->Like->save($d,true,array("post_id","user_id"))){
- $this->redirect($this->referer());
- }
- }
- }
- }
- function like() {
- $user_id = $this->Auth->user("id");
- if (!$user_id) {
- $this->redirect("/");
- die();
- }
- if ($this->request->is("post")) {
- $this->Like->create();
- if ($this->Like->save($this->request->data, true, array("post_id", "user_id"))) {
- $this->redirect($this->referer());
- }
- }
- }
Add Comment
Please, Sign In to add comment