/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Chat::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, 'userId' => $this->userId, 'updateDate' => $this->updateDate]); $query->andFilterWhere(['like', 'message', $this->message]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getChats() { return $this->hasMany(Chat::className(), ['user_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getChat() { return $this->hasOne(Chat::className(), ['id' => 'chat_id']); }
public function actionExcel() { $searchModel = new ChatSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $modelAttribute = new Chat(); $not = Util::excelNot(); foreach ($modelAttribute->attributeLabels() as $k => $v) { if (!in_array($k, $not)) { $attributes[$k] = $v; } } $models = $dataProvider->getModels(); $objReader = \PHPExcel_IOFactory::createReader('Excel5'); $objPHPExcel = $objReader->load(Yii::getAlias(Util::templateExcel())); $excelChar = Util::excelChar(); return $this->render('_excel', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'attributes' => $attributes, 'models' => $models, 'objReader' => $objReader, 'objPHPExcel' => $objPHPExcel, 'excelChar' => $excelChar]); }