/** * 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(); 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 Article model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Article(); if ($model->load(\App::$app->request->post())) { $model->logo = UploadedFile::getInstance($model, 'logo'); if ($model->logo) { $contractName = mt_rand(1100, 9900) . time() . '.' . $model->logo->extension; $model->logo->saveAs('upload/' . $contractName); $model->logo = $contractName; } $model->user_id = \App::$app->request->post()['Article']['user_id']; $model->category_id = \App::$app->request->post()['Article']['category_id']; $model->title = \App::$app->request->post()['Article']['title']; $model->intro = \App::$app->request->post()['Article']['intro']; $model->content = \App::$app->request->post()['Article']['content']; $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }