protected function commentValidateOne() { setContentType("json"); $comment = new Comment(); $given = array_keys($_POST); $response["error"] = null; if (count($given) == 1) { if ($given[0] == "text") { $comment->setText($_POST["text"]); } if (!$comment->validate()) { foreach ($comment->getValidationFailures() as $failure) { if ($given[0] == $failure->getPropertyPath()) { $response["error"] = array("name" => $failure->getPropertyPath(), "message" => $failure->getMessage()); } } } $this->viewString(json_encode($response)); } }
protected function comment($id) { //TODO: check rights $note = NoteQuery::create()->findPK($id); $comment = new Comment(); $comment->setUser($this->params['user']); $comment->setNote($note); $comment->setText($_POST['msg']); $comment->save(); $this->params['comments'] = $note->getComments(); $this->renderType('js.phtml'); }