/** * Creates a new Advert model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Advert(); 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 Advert model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $user = User::findOne(['id' => Yii::$app->user->id]); // $pic = new UploadForm(); $catList = ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'name'); $subcatList = ArrayHelper::map(Subcategory::find()->asArray()->all(), 'id', 'name'); $regionList = ArrayHelper::map(Region::find()->asArray()->all(), 'id', 'name'); $cityList = ArrayHelper::map(City::find()->asArray()->all(), 'id', 'name'); $model = new Advert(); if ($model->load(Yii::$app->request->post())) { if ($model->createAdvert()) { return $this->redirect(['upload']); } return $this->render('create', ['model' => $model, 'user' => $user, 'catList' => $catList, 'subcatList' => $subcatList, 'regionList' => $regionList, 'cityList' => $cityList]); } return $this->render('create', ['model' => $model, 'user' => $user, 'catList' => $catList, 'subcatList' => $subcatList, 'regionList' => $regionList, 'cityList' => $cityList]); }