findComment() публичный статический Метод

通过ID获取指定评论
public static findComment ( $id ) : array | null | ActiveRecord | static
$id
Результат array | null | yii\db\ActiveRecord | static
Пример #1
0
 public function userDoAction($id, $action)
 {
     $comment = PostComment::findComment($id);
     $user = \Yii::$app->user->getIdentity();
     if (in_array($action, ['like'])) {
         return UserService::CommentAction($user, $comment, $action);
     }
 }
Пример #2
0
 /**
  * 伪删除
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  */
 public function actionDelete($id)
 {
     $model = PostComment::findComment($id);
     if (!$model->isCurrent()) {
         throw new NotFoundHttpException();
     }
     // 事物 暂时数据库类型不支持 无效
     $transaction = \Yii::$app->db->beginTransaction();
     $updateComment = $model->updateCounters(['status' => -1]);
     $updateNotify = Notification::updateAll(['status' => 0], ['comment_id' => $model->id]);
     $updateTopic = Topic::updateAllCounters(['comment_count' => -1], ['id' => $model->post_id]);
     if ($updateNotify && $updateComment && $updateTopic) {
         $transaction->commit();
     } else {
         $transaction->rollback();
     }
     return $this->redirect(['/topic/default/view', 'id' => $model->post_id]);
 }