Ejemplo n.º 1
0
 /**
  * Creates a new GoodsParamsName model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new GoodsParamsName();
     $arPost = Yii::$app->request->post();
     if (Yii::$app->request->getIsPost()) {
         $arPost['GoodsParamsName']['goods_type_type'] = $this->goodType;
         $arPost['GoodsParamsName']['id'] = str_replace($this->goodType . '_', '', $arPost['GoodsParamsName']['id']);
         $arPost['GoodsParamsName']['id'] = $this->goodType . '_' . $arPost['GoodsParamsName']['id'];
     }
     if (Yii::$app->request->getIsPost() && $model->load($arPost) && $model->save()) {
         $arPost['GoodsParamsName']['id'] = str_replace($this->goodType . '_', '', $arPost['GoodsParamsName']['id']);
         $arPost['GoodsParamsName']['id'] = $this->goodType . '_' . $arPost['GoodsParamsName']['id'];
         $table = 'goods_t_' . $this->goodType;
         $fild = $arPost['GoodsParamsName']['id'];
         $dataType = $arPost['GoodsParamsName']['data_type'];
         $required = $arPost['GoodsParamsName']['required'] ? ' NOT NULL' : '';
         //            $sql = "ALTER TABLE `$table` ADD `$fild` $dataType $required";
         $sql = "ALTER TABLE `{$table}` ADD `{$fild}` int(7) {$required}";
         \Yii::$app->db->createCommand($sql)->execute();
         // ALTER TABLE `goods_t_tyre` ADD `with` INT NOT NULL
         return $this->redirect(['index']);
     } else {
         $listTypesParams = ['' => ' - - ', 'int' => 'Целое число', 'float' => 'Число с запятой', 'varchar' => 'Строка'];
         $parentParam = GoodsParamsName::find()->where('goods_type_type=:goods_type', [':goods_type' => $this->goodType])->all();
         $arParams = ['' => ' - - '];
         foreach ($parentParam as $value) {
             $arParams[$value->id] = $value->name;
         }
         return $this->render('create', ['listTypesParams' => $listTypesParams, 'model' => $model, 'arParams' => $arParams]);
     }
 }