/** * 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]); }
public function actionCreateArticle() { $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); \Yii::$app->session->setFlash('success', '投稿成功,请等待管理员审核!'); return $this->redirect(['create-article']); } } } return $this->render('create-article', ['model' => $model, 'dataModel' => $dataModel]); }