public function actionDelete()
 {
     $id = Yii::$app->request->get('id', 0);
     if ($id > 0) {
         $comment = Comments::findOne(['id' => $id]);
         return $comment->deleteWithChildren();
     }
     return false;
 }
 public function actionUpdate($id)
 {
     $comment = Comments::findOne($id);
     if (Yii::$app->user->identity->level > 1 or Yii::$app->user->identity->id == $comment->id_user) {
         $login = new login();
         if ($comment->load(Yii::$app->request->post()) && $comment->save()) {
             return $this->redirect(['/news/view', 'id' => $comment->id_new]);
         } else {
             return $this->render('update', ['comment' => $comment, 'login' => $login]);
         }
     }
 }
 /**
  * Finds the Comments model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comments the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comments::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #4
0
 /**
  * Finds the Comments model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comments the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comments::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Strona nie istnieje.');
     }
 }