예제 #1
0
 /**
  * Finds the Comment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Comment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #2
0
 private function findComment($id)
 {
     if ($comment = Comment::findOne($id)) {
         return $comment;
     } else {
         throw new NotFoundHttpException();
     }
 }
예제 #3
0
 /**
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  * @throws \Exception
  */
 public function actionDelete($id)
 {
     /** @var Comment $model */
     $model = Comment::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException();
     }
     $model->delete();
     return $this->redirect(['list']);
 }
예제 #4
0
 /**
  * Удаление комментария
  * @param  integer $id   Идентификатор удаляемой записи
  * @return redirect      После выполнения редиректит на главную.
  */
 public function actionDelete($id)
 {
     //Определение текущего языка
     SiteController::locale();
     //Поиск по идентификатору
     $comment = Comment::findOne($id);
     //В зависимости от успеха удаления, пишет в память сообщение от успехе или лог ошибок
     if ($comment->delete()) {
         Yii::$app->session->setFlash('success', Yii::t('msg/msg', 'Комментарий удален'));
     } else {
         Yii::$app->session->setFlash('errors', $comment->errors);
     }
     return $this->redirect("/");
 }
 public static function removeComment(\common\components\Comment $comment)
 {
     return Comment::findOne($comment->getId())->delete();
 }
예제 #6
0
 /**
  * inline update comment
  */
 public function actionInlineUpdateComment()
 {
     $id = Yii::$app->request->get('id');
     $comment = \app\models\Comment::findOne($id);
     $currentUserId = \app\components\OvcUser::getCurrentUser()->id;
     echo $this->renderPartial('_edit_comment_on_video', ['comment' => $comment, 'currentUserId' => $currentUserId]);
 }
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         $this->setHeader(400);
         echo json_encode(array('status' => 0, 'error_code' => 400, 'message' => 'Bad request'), JSON_PRETTY_PRINT);
         exit;
     }
 }
예제 #8
0
 /**
  * inline save
  * @throws \yii\web\ForbiddenHttpException
  */
 public function actionInlineSave()
 {
     $id = Yii::$app->request->post('id');
     $model = Comment::findOne($id);
     if (!Yii::$app->request->isAjax || !is_object($model)) {
         throw new \yii\web\ForbiddenHttpException('Illegal Request.');
     }
     $model->text = Yii::$app->request->post('text');
     if ($model->save()) {
         Yii::$app->runAction('video/get-comment-by-id', ['id' => $model->id]);
     }
 }