/** * 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]); } }