/** * 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(); $model->user_id = Yii::$app->user->id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
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]); }