Example #1
0
 /**
  * Creates a new Answer model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * 
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Answer();
     $post = Yii::$app->request->post();
     if (isset($post['Answer']['content']) && isset($post['Answer']['askId'])) {
         $model->load($post);
         $model->userId = Yii::$app->user->identity->getId();
         $model->createTime = date('Y-m-d H:i:s', time());
         $model->status = 1;
         $model->helpNum = 0;
         if ($model->save()) {
             $main = Main::findOne($post['Answer']['askId']);
             $main->status = 2;
             $main->save();
         }
     }
     return $this->redirect(['/main/view', 'id' => $post['Answer']['askId']]);
 }
Example #2
0
 /**
  * Finds the Main model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id            
  * @return Main the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Main::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }