Esempio n. 1
0
 /**
  * Creates a new Thread model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionNewThread()
 {
     if (!YiiForum::checkAuth('thread_add')) {
         return $this->noPermission();
     }
     YiiForum::checkIsGuest();
     $boardId = YiiForum::getGetValue('boardid');
     $model = new Thread();
     if ($model->load(Yii::$app->request->post())) {
         $model->board_id = $boardId;
         $model->user_id = $model->last_user_id = YiiForum::getIdentity()->id;
         $model->user_name = $model->last_user_name = YiiForum::getIdentity()->username;
         $model->create_time = $model->modify_time = $model->last_modify_time = TTimeHelper::getCurrentTime();
         if ($model->save()) {
             $this->savePostForThread($model);
         }
         Board::updateLastData($boardId, $model['id'], $model['title']);
         return $this->redirect(['view', 'id' => $model->id, 'boardid' => $boardId]);
     } else {
         $locals = [];
         $locals['model'] = $model;
         $locals['currentBoard'] = $this->getBoard($boardId);
         return $this->render('new-thread', $locals);
     }
 }
Esempio n. 2
0
 /**
  * Creates a new Thread model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->checkIsGuest();
     $boardId = $this->getGetValue('boardid');
     $model = new Thread();
     if ($model->load(Yii::$app->request->post())) {
         $model->board_id = $boardId;
         $model->user_id = $this->identity->id;
         $model->user_name = $this->identity->username;
         $model->create_time = $this->getCurrentTime();
         $model->modify_time = $this->getCurrentTime();
         if ($model->save()) {
             $this->savePostForThread($model);
         }
         //$this->info($model,__METHOD__);
         return $this->redirect(['view', 'id' => $model->id, 'boardid' => $boardId]);
     } else {
         $locals = [];
         $locals['model'] = $model;
         $locals['currentBoard'] = $this->getBoard($boardId);
         return $this->render('create', $locals);
     }
 }