/** * Creates a new Categories model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Categories(); 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 Categories model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Categories(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', 'Your information saved.'); return $this->redirect(['index']); echo Yii::$app->session->getFlash('success'); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $categ = new Categories(); if ($categ->load(Yii::$app->request->post()) && $categ->validate()) { //return print_r($_POST); $categ['categ_active_from'] = date("Y-m-d"); $categ->save(); return $this->redirect('index'); } $inco_ex = new IncoExpenso(); $inco_ex = $inco_ex->find()->all(); return $this->render('create', ['categ' => $categ, 'inco_ex' => $inco_ex]); }
/** * Creates a new Categories model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Categories(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->parent_id > 0) { return $this->redirect(['subcat', 'SearchCategories[parent_id]' => $model->parent_id]); } else { return $this->redirect(['/categories']); } } else { return $this->render('create', ['model' => $model, 'parent_id' => Yii::$app->request->queryParams["parent_id"]]); } }
/** * Импорт категорий * * @param $path * @return array|\yii\db\ActiveRecord[] */ private function importCategories($path) { $file = $path . DIRECTORY_SEPARATOR . 'category_info.csv'; $row = 1; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 0, ";")) !== FALSE) { $row++; $this->stdout("Row " . $row . ":\n"); $model = Categories::findOne($data[0]); if ($model === null) { $model = new Categories(['id' => $data[0], 'category_name' => $data[1], 'file_name' => $data[2]]); } if ($model->save()) { $this->stdout("Category {$model->id} with name '{$model->category_name}' imported\n"); } $this->stdout("\n"); } } else { return false; } return Categories::find()->all(); }