/** * Creates a new Service model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Service(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $redirect = yii::$app->request->post('goto') == 'list' ? ['index'] : ['update', 'id' => $model->id]; return $this->redirect($redirect); } return $this->render('create', ['model' => $model]); }
/** * Creates a new Service model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Service(); 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 Service model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Service(); $secServiceList = SecService::find()->select(['id', 'header'])->all(); $secServiceList = ArrayHelper::map($secServiceList, 'id', 'header'); // или // $secServiceList = SecService::find()->select(['header', 'id'])->indexBy('id')->column(); if ($model->load(Yii::$app->request->post())) { $transaction = Service::getDb()->beginTransaction(); if ($model->save()) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } else { $transaction->rollBack(); return $this->render('create', ['model' => $model, 'secServiceList' => $secServiceList]); } } else { return $this->render('create', ['model' => $model, 'secServiceList' => $secServiceList]); } }