/** * Post detail * @param string $uri URI of post */ public function actionView($uri) { /** * Post data */ $post = $this->db->post()->where('uri', $uri)->fetch(); if ($post) { $data['page_title'] = $post['title']; } else { $this->notFound(); } $data['post'] = $post; $data['postComments'] = $this->db->comment()->where('post_id', $post['id'])->order('created DESC'); /** * Comments */ $form = new Forms('newComment'); $form->successMessage = 'Your comment was saved.'; $form->errorMessage = 'Error while saving comment. Try it later.'; $form->addInput('text', 'name', 'Name'); $form->addInput('email', 'email', 'E-mail', true); $form->addTextArea('comment', 'Your comment', true, '', 2); $form->addSubmit('send', 'Send commment'); if ($form->isValid()) { $formValues = $form->values(); $saveComment = $this->db->comment()->insert(array('post_id' => $post['id'], 'name' => $formValues['name'] ? $formValues['name'] : null, 'email' => $formValues['email'] ? $formValues['email'] : null, 'comment' => $formValues['comment'] ? $formValues['comment'] : null, 'created' => new NotORM_Literal("NOW()"), 'ip' => $this->realClientIp())); if ($saveComment) { $form->success(); } else { $form->error(); } } $data['comment_form'] = $form->formHtml(); $this->renderTemplate('post/view', $data); }