Пример #1
0
 /**
  * Creates a new Tmp model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tmp();
     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 {
             return $this->redirect(['create', 'typeid' => Yii::$app->request->get('typeid')]);
         }
     } else {
         $model->images = [['label' => '示例图片'], ['label' => '额外图片']];
         $model->configs = ['configs' => [['属性名', 'tmpc_name'], ['默认值', 'tmpc_value'], ['键值', 'tmpc_key']], 'data' => array()];
         $model->imgconfigs = ['configs' => [['图片名', 'tmpimg_name'], ['宽度', 'tmpimg_width'], ['高度', 'tmpimg_height']], 'data' => array()];
         $model->is_use = 1;
         $model->type = Yii::$app->request->get('typeid');
         //所属插件的id
         $tmpid = Tmp::find()->where(['type' => $model->type])->select('Max(tmpid) as mtmpid')->asArray()->one();
         if (empty($tmpid['mtmpid'])) {
             $new_tmpid = 1;
         } else {
             $new_tmpid = $tmpid + 1;
         }
         $model->tmpid = $new_tmpid;
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tmp::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'is_use' => $this->is_use, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'images', $this->images])->andFilterWhere(['like', 'configs', $this->configs])->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'updated_at', $this->updated_at]);
     return $dataProvider;
 }