/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Media::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, 'material' => $this->material, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'mediaId', $this->mediaId])->andFilterWhere(['like', 'post', $this->post])->andFilterWhere(['like', 'result', $this->result])->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
/** * 素材表 */ public function initMediaTable() { $tableName = Media::tableName(); $this->createTable($tableName, ['id' => Schema::TYPE_PK, 'mediaId' => Schema::TYPE_STRING . "(100) NOT NULL DEFAULT '' COMMENT '素材ID'", 'filename' => Schema::TYPE_STRING . "(100) NOT NULL COMMENT '文件名'", 'result' => Schema::TYPE_TEXT . " NOT NULL COMMENT '微信返回数据'", 'type' => Schema::TYPE_STRING . "(10) NOT NULL DEFAULT '' COMMENT '素材类型'", 'material' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '素材类别'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'"]); }
/** * Finds the Media model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Media the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Media::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }