/** * Creates a new Country model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Country(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $uploadedFile = UploadedFile::getInstance($model, 'flag'); $model->save(false); if (!empty($uploadedFile)) { // Save origionals $originalAsset = new Asset(); $originalAsset->assetable_type = Asset::ASSETABLE_COUNTRY; $originalAsset->assetable_id = $model->id; $originalAsset->uploadedFile = $uploadedFile; $originalAsset->saveAsset(); // Save thumbnails $imageID = $originalAsset->id; $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_COUNTRY); foreach ($thumbnails as $thumbnail) { $asset = new Asset(); $asset->assetable_type = Asset::ASSETABLE_COUNTRY; $asset->assetable_id = $model->id; $asset->parent_id = $imageID; $asset->thumbnail = $thumbnail; $asset->uploadedFile = $uploadedFile; $asset->saveAsset(); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Country model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Country(); 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 Country model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Country(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('app', 'Saved')); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Country model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Country(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->Response->format = 'json'; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { $model->save(); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Country model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Country(); $searchModel = new CountrySearch(); $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); if ($model->load(Yii::$app->request->post())) { if (\Yii::$app->request->isAjax) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } $model->attributes = $_POST['Country']; $model->create_at = new \yii\db\Expression('NOW()'); $model->update_at = new \yii\db\Expression('NOW()'); if ($model->save()) { return $this->redirect(['index']); } } else { return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } }