/** * Creates a new Items model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Items(); 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 actionCreate() { $this->layout = 'admin'; $model = new Items(); $uploadFile = new UploadForm(); $uploadImg = new UploadForm(); if (Yii::$app->request->isPost) { $uploadFile->file = UploadedFile::getInstance($uploadFile, 'file'); $uploadImg->img = UploadedFile::getInstance($uploadImg, 'img'); if ($uploadFile->file && $uploadFile->validate()) { $uploadFile->file->saveAs('uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension); } elseif ($uploadImg->img && $uploadImg->validate()) { $uploadImg->img->saveAs('uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension); } else { print_r($uploadFile->getErrors()); } } if ($model->load(Yii::$app->request->post())) { $model->text = Yii::$app->request->post('Items')['text']; $model->tags = Yii::$app->request->post('Items')['tags']; $model->title = Yii::$app->request->post('Items')['title']; $model->cens = Yii::$app->request->post('Items')['cens']; //$model->cat_id = Yii::$app->request->post('Items')['cat_id']; if (Categories::find()->where(['title' => Yii::$app->request->post('Items')['cat_title']])->one()) { $model->cat_id = Categories::find()->where(['title' => Yii::$app->request->post('Items')['cat_title']])->one()->id; } $model->audio_link = Yii::$app->request->post('Items')['audio_link']; $model->in_work_prim = Yii::$app->request->post('Items')['in_work_prim']; $model->play_status = 1; //if(isset(Yii::$app->request->post('Items')['source_id']))$model->source_id = Yii::$app->request->post('Items')['source_id']; //else $model->source_id = 2; if (Source::find()->where(['title' => Yii::$app->request->post('Items')['source_title']])->one()) { $model->source_id = Source::find()->where(['title' => Yii::$app->request->post('Items')['source_title']])->one()->id; } else { $model->source_id = 2; } if (isset($uploadFile->file)) { $model->audio = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension; } if (isset($uploadImg->img)) { $model->img = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension; } $model->save(false); //var_dump($model->id); exit; Tag::addTags($model->tags, $model->id); return $this->redirect(Url::toRoute('item/index')); } else { return $this->render('_form', ['model' => $model, 'uploadFile' => $uploadFile, 'uploadImg' => $uploadImg]); } }
/** * */ public function actionInsertitem() { $arr['XH_ID'] = \Yii::$app->user->identity->XH_ID; $arr['Item_Name'] = \yii\helpers\Html::encode($_POST["ItemName"]); $arr['Item_Intro'] = \yii\helpers\Html::encode($_POST["ItemIntro"]); $arr['Status'] = 1; $arr['Date'] = date('y-m-d'); $item = new Items(); $item->XH_ID = $arr['XH_ID']; $item->Item_Name = $arr['Item_Name']; $item->Item_Intro = $arr['Item_Intro']; $item->Status = $arr['Status']; $item->Date = $arr['Date']; $result = $item->save(false); if ($result) { echo '{"success": true}'; } else { echo '{"success": false}'; } }
public function actionCreate() { $model = new Items(); $upload = new UploadForm(); $category = new Categories(); $subCat = new SubCatgories(); $category->find()->all(); $subCat->find()->all(); $model->is_aviable = 1; $description = new Description(); $description->item_id = 1; $description->sub_id = 1; $description->text = "s"; $description->save(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if (isset($_POST['Description'])) { // print_r($_POST['Description']['sub_name']); $subCat = new SubCatgories(); $subCat->find()->where(['name' => $_POST['Description']['sub_name']])->all(); $s = $subCat->find()->where(['name' => $_POST['Description']['sub_name']])->all(); $description = new Description(); $description->item_id = $model->id; $description->sub_id = $s[0]['id']; $description->text = $_POST['Description']['text']; $description->category_name = $_POST['Description']['category_name']; $description->sub_name = $_POST['Description']['sub_name']; $description->save(); // echo "sssss"; // echo $description->sub_id; // echo $description->item_id; } if (isset($_POST['Description'])) { $upload = new UploadForm(); $upload->imageFiles = UploadedFile::getInstances($upload, 'imageFiles'); if ($upload->upload()) { echo "upload"; // file is uploaded successfully // return; } } // else // return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'category' => $category, 'subCat' => $subCat, 'description' => $description, 'upload' => $upload]); } }