예제 #1
0
 private function processDelete()
 {
     $delete = (int) \Yii::$app->getRequest()->get('delete-comment');
     if ($delete > 0) {
         /** @var Comments\models\Comment $Comment */
         $Comment = Comments\models\Comment::find()->byId($delete)->one();
         if ($Comment->isDeleted()) {
             return;
         }
         if (!$Comment instanceof Comments\models\Comment) {
             throw new \yii\web\NotFoundHttpException(\Yii::t('app', 'Comment not found.'));
         }
         if (!$Comment->canDelete()) {
             throw new \yii\web\ForbiddenHttpException(\Yii::t('app', 'Access Denied.'));
         }
         $Comment->deleted = Comments\models\Comment::DELETED;
         $Comment->update();
     }
 }
예제 #2
0
 /**
  * @return bool
  * @throws \yii\web\NotFoundHttpException
  */
 public function save()
 {
     $Comment = $this->Comment;
     if (empty($this->id)) {
         $Comment = new Comments\models\Comment();
     } elseif ($this->id > 0 && $Comment->id !== $this->id) {
         $Comment = Comments\models\Comment::find()->byId($this->id)->one();
         if (!$Comment instanceof Comments\models\Comment) {
             throw new \yii\web\NotFoundHttpException();
         }
     }
     $Comment->entity = $this->entity;
     $Comment->text = $this->text;
     $result = $Comment->save();
     if ($Comment->hasErrors()) {
         foreach ($Comment->getErrors() as $attribute => $messages) {
             foreach ($messages as $mes) {
                 $this->addError($attribute, $mes);
             }
         }
     }
     $this->Comment = $Comment;
     return $result;
 }
예제 #3
0
 /**
  * Displays a single Post model.
  * @param string $id
  * @return mixed
  */
 public function actionView($id)
 {
     return $this->render('view', ['model' => $this->findModel($id), 'category' => Category::find()->all(), 'comment_list' => Comment::find()->all()]);
 }