public function getRecomment($page = 0) { return $this->hasMany(Recomment::className(), ['comment_id' => 'id'])->offset($page * 5)->limit(10)->orderBy('reply_time'); }
public function actionAddRecomment() { if (Yii::$app->request->isPost) { $session = Yii::$app->session; if (!$session->isActive) { $session->open(); } if (!isset($session['user'])) { $this->redirect('?r=login'); } $user_id = $session['user']['userid']; $user_name = $session['user']['name']; $request = Yii::$app->request; $chapterid = $request->post('chapterid'); $commentid = $request->post('commentid'); $commentname = $request->post('commentname'); $content = $request->post('recommentcontent'); $recommentmodel = new Recomment(); $recommentmodel->comment_id = $commentid; $recommentmodel->replyer = $user_name; $recommentmodel->recomment_name = $commentname; $recommentmodel->reply_content = $content; $recommentmodel->reply_time = date("Y-m-d H:i:s", time()); if ($content != "") { $recommentmodel->save(); } return $this->redirect(['comment', 'id' => $chapterid]); } }