public function post_xhr($post_id) { // Bob Loblaw never got around to implementing this, here is pseudo PHP if (is_valid_post($post_id)) { // Assuming you save this comment, just return JSON if the post exists echo json_encode(array('commentor' => $_POST['commentor'], 'comment_body' => $_POST['comment_body'])); } }
function post_by_url($post_url = "") { if (!is_valid_post($post_url)) { $this->session->set_flashdata("error", "Invalid post title."); redirect("posts"); exit; } if ($this->input->post()) { $this->form_validation->set_rules("comment", "Comment", "xss_clean|required"); if ($this->form_validation->run()) { $array["post_id"] = $this->input->post("post_id"); $array["comment"] = $this->input->post("comment"); $array["commented_by"] = $this->session->userdata("user_id"); $array["created_on"] = time(); $add_comment = $this->Post_model->add_post_comment($array); if ($add_comment) { redirect("post/" . $post_url); } } } /* because of routing conditions, taking first parameter as post URL */ $data["posts"] = $this->Post_model->get_post_by_url($post_url); $data["share_count"] = $this->Post_model->get_share_count_by_post_id($data['posts']['data']['id']); $data["header"] = true; $data["_view"] = "post/post_by_url"; $data["footer"] = true; $this->load->view("layout/baseTemplate", $data); }