/** * Creates a new Section model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Article(); $model->scenario = 'create'; if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (Yii::$app->request->post('isPublish', 0) == 1) { $model->status = Section::STATUS_PUBLISH; } $model->create(); return $this->redirect(['view', 'id' => $model->id]); } else { Yii::$app->session->set('KCFINDER', ['disabled' => false, 'uploadURL' => '/upload', 'uploadDir' => '../../../backend/web/upload']); return $this->render('create', ['model' => $model]); } }
/** * Creates a new Article model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Article(); $dataModel = new ArticleData(); if ($model->load(Yii::$app->request->post()) && $dataModel->load(Yii::$app->request->post())) { $isValid = $model->validate(); if ($isValid) { $model->save(false); $dataModel->id = $model->id; $isValid = $dataModel->validate(); if ($isValid) { $dataModel->save(false); return $this->redirect(['index']); } } } return $this->render('create', ['model' => $model, 'dataModel' => $dataModel]); }