/** * Creates a new CoachPosts model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new CoachPosts(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new CoachPosts model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id = 0) { $model = new CoachPosts(); if ($id != 0) { $model->business_id = $id; } //TODO::封装成独立函数 $businesses = []; $pending_businesses = Business::find()->where('is_recommend=:r', [':r' => 0])->all(); foreach ($pending_businesses as $business) { $businesses[$business->id] = $business->business_number; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->release_time = time(); $model->admin_id = \Yii::$app->session['userid']; if ($model->save()) { $business = Business::find()->where('id=:id', [':id' => $model->business_id])->one(); $business->has_post = 1; return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model, 'businesses' => $businesses]); }