Пример #1
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $modelCategory = new Category();
     $categoriesArray = ArrayHelper::map(Category::find()->all(), 'id', 'name');
     $categories = Category::find()->all();
     $subCategoriesArray = SubCategory::find()->all();
     //        if ($model->load(Yii::$app->request->post())){
     //
     //            var_dump($_POST);
     //        die();
     //        }
     //var_dump($_POST);
     //echo "<br>";
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         foreach (Yii::$app->request->post()['category'] as $key => $id) {
             //var_dump($id.'---');
             foreach (Yii::$app->request->post()['subCategory' . $id] as $keySub => $idSub) {
                 //$linkProductArray = array($model->id,$id,$idSub);
                 $modelLinkProduct = new LinkProduct();
                 //var_dump($keySub.$idSub );echo "<br>";
                 $modelLinkProduct->id_product = $model->id;
                 $modelLinkProduct->id_category = $id;
                 $modelLinkProduct->id_sub_category = $idSub;
                 $modelLinkProduct->save();
             }
         }
         //die();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('_form-create.php', ['model' => $model, 'categoriesArray' => $categoriesArray, 'categories' => $categories, 'subCategoriesArray' => $subCategoriesArray]);
     }
 }
Пример #2
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->product_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #3
0
 public function actionCreate()
 {
     $model = new Product();
     if ($model->isNewRecord) {
         $model->active = 1;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $this->fileAttach($model);
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'listCategory' => Category::getListCategory()]);
     }
 }