/** * Creates a new Thread model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Thread(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Displays a single Board model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); if ($model->parent_id == Board::AS_CATEGORY) { return $this->render('boards', ['model' => $model, 'forum' => $model->forumModel, 'parentId' => $model->id]); } $newThread = new Thread(); if ($newThread->load(Yii::$app->request->post())) { $newThread->board_id = $model->id; if ($newThread->save()) { Yii::$app->db->createCommand()->update('{{%forum_board}}', ['updated_at' => time(), 'updated_by' => Yii::$app->user->id], 'id=:id', [':id' => $model->id])->execute(); return $this->refresh(); } } return $this->render('view', ['model' => $model, 'newThread' => $newThread]); }
/** * Displays a single Board model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); //如果是该版块是个分类,则返回该分类下所有版块列表 if ($model->parent_id == Board::AS_CATEGORY) { return $this->render('boards', ['model' => $model, 'forum' => $model->forum, 'parentId' => $model->id]); } $newThread = new Thread(); if ($newThread->load(Yii::$app->request->post())) { $newThread->board_id = $model->id; if ($newThread->save()) { //更新该版块最后回复信息 Yii::$app->db->createCommand()->update('{{%forum_board}}', ['updated_at' => time(), 'updated_by' => Yii::$app->user->id], 'id=:id', [':id' => $model->id])->execute(); Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Create successfully.')); return $this->redirect(['/forum/thread/view', 'id' => $newThread->id]); } } return $this->render('view', ['model' => $model, 'newThread' => $newThread]); }
protected function newThread($id) { $newThread = new Thread(); if ($newThread->load(Yii::$app->request->post())) { $newThread->board_id = $id; $newThread->save(); Yii::$app->db->createCommand()->update('{{%forum_board}}', ['updated_at' => time(), 'updated_by' => Yii::$app->user->id], 'id=:id', [':id' => $id])->execute(); $this->refresh(); } return $newThread; }