protected function addComment($name, $email, $website, $body, $postId, &$errors) { $success = false; $comment = Comments::create(array('name' => $name, 'email' => $email, 'website' => $website, 'body' => $body, 'post_id' => $postId)); if (!($success = $comment->save())) { $errors = $comment->errors(); } return $success; }
/** * Run the database seeds. * * @return void */ public function run() { Comments::truncate(); $time = Carbon::now('Asia/Taipei')->subweeks(2); foreach (range(1, 10) as $value) { $time->addDay(); Comments::create(['name' => '路人甲' . rand(1, 10), 'content' => '假留言' . $value, 'article_id' => rand(1, 8), 'created_at' => $time, 'updated_at' => $time]); } }
/** * Add member post * */ public static function add() { if (!Request::is_authenticated()) { Session::push('flash-message', 'You must login before!'); Response::redirect('login'); } if ("POST" == Request::method()) { $id_member = Request::POST()->member_id; $id_post = Request::POST()->post_id; $comment = Request::POST()->comment; Comments::create($id_post, $id_member, $comment); Response::redirect(isset($_GET['next']) ? Request::GET()->next . '#comment' : ''); } else { Response::redirect(''); } }
public function actionView($id, $ajax = false) { $login = new login(); $comment = new Comments(); $getComments = Comments::find()->where(['id_new' => $id]); $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $getComments->count()]); $getComments = $getComments->offset($pagination->offset)->limit($pagination->limit)->all(); if ($comment->load(Yii::$app->request->post()) && $comment->create($id)) { return $this->redirect(['view', 'id' => $id]); } else { if ($ajax == true) { return $this->renderAjax('ajaxComment', ['login' => $login, 'comment' => $comment, 'getComments' => $getComments, 'pagination' => $pagination]); } else { return $this->render('view', ['login' => $login, 'model' => $this->findModel($id), 'comment' => $comment, 'getComments' => $getComments, 'pagination' => $pagination]); } } }
/** * Create comment in activity stream * * @param $streamId * @param $userId * @param $comment * @return bool */ public function saveActivityComment($streamId, $userId, $comment) { $results = $this->commentsModel->create(['stream_id' => $streamId, 'user_id' => $userId, 'comment' => $comment]); return $results; }