Пример #1
0
 /**
  * Updates an existing Tmp model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if (!Yii::$app->request->get('typeid')) {
         UHelper::alert('参数缺失,无法添加模板', 'error');
         return $this->redirect(['plug/index']);
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->images = JquploadHelper::jqformat();
         $model->configs = ArrayHelper::mulitinput(['tmpc_name', 'tmpc_value', 'tmpc_key']);
         $model->imgconfigs = ArrayHelper::mulitinput(['tmpimg_name', 'tmpimg_width', 'tmpimg_height']);
         if ($model->save()) {
             UHelper::alert('更新成功!', 'success');
             return $this->redirect(['index', 'typeid' => Yii::$app->request->get('typeid')]);
         } else {
             UHelper::alert('更新失败!', 'error');
             return $this->redirect(['update', 'id' => $id, 'typeid' => Yii::$app->request->get('typeid')]);
         }
     } else {
         $model->images = JquploadHelper::jqunformat($model->images);
         $model->configs = ['configs' => [['属性名', 'tmpc_name'], ['默认值', 'tmpc_value'], ['键值', 'tmpc_key']], 'data' => Json::decode($model->configs, 1)];
         $model->imgconfigs = ['configs' => [['图片名', 'tmpimg_name'], ['宽度', 'tmpimg_width'], ['高度', 'tmpimg_height']], 'data' => Json::decode($model->imgconfigs, 1)];
         //            UHelper::output($model->configs);
         return $this->render('update', ['model' => $model]);
     }
 }