/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Wechat::find()->where(['user_id' => Yii::$app->user->id]); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['type' => $this->type, 'status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'wechat_id', $this->wechat_id])->andFilterWhere(['like', 'i', $this->i]); return $dataProvider; }
public function setOptions() { $request = Yii::$app->getRequest(); $wid = $request->get('id'); $info = Wechat::find()->where(['id' => $wid])->asArray()->one(); if (!$info) { throw new NotFoundHttpException('The requested wechat does not exist.'); } $session = Yii::$app->session; $wechat = ['app_id' => $info['appid'], 'secret' => $info['secret'], 'token' => $info['token'], 'id' => $info['id']]; $session['wechat'] = $wechat; }
/** * Updates an existing Menu model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed * @throws NotFoundHttpException */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'i' => $model->w_id]); } else { $wechat = Wechat::find()->where(['id' => $this->wid])->one(); if (!$wechat) { throw new NotFoundHttpException("没有此公众号信息"); } $model->type = Menu::TYPE_URL; return $this->render('update', ['model' => $model, 'wechat' => $wechat]); } }
/** * Finds the Wechat model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Wechat the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Wechat::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo $form->field($model, 'secret')->textInput(['maxlength' => true])->hint('在微信公众平台基本配置中查看'); ?> <?php echo $form->field($model, 'token')->textInput(['maxlength' => true])->hint('添写与公众号中配置一至的token'); ?> <?php echo $form->field($model, 'encodekey')->textInput(['maxlength' => true])->hint('添写与公众号中配置一至的消息加解密密钥'); ?> <?php echo $form->field($model, 'type')->radioList(Wechat::typeMap())->hint('请与公众号中配置一至'); ?> <div class="form-group"> <div class="col-sm-offset-2 col-sm-3"> <?php echo Html::submitButton('保 存', ['class' => 'btn btn-primary btn-block']); ?> </div> </div> <?php ActiveForm::end(); ?> </div>