コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 public function actionSample()
 {
     //$objPHPExcel = new \PHPExcel();
     $template = Util::templateExcel();
     $model = new Chat();
     $date = date('YmdHis');
     $name = $date . 'Chat';
     //$attributes = $model->attributeLabels();
     $models = Chat::find()->all();
     $excelChar = Util::excelChar();
     $not = Util::excelNot();
     foreach ($model->attributeLabels() as $k => $v) {
         if (!in_array($k, $not)) {
             $attributes[$k] = $v;
         }
     }
     $objReader = \PHPExcel_IOFactory::createReader('Excel5');
     $objPHPExcel = $objReader->load(Yii::getAlias($template));
     return $this->render('sample', ['models' => $models, 'attributes' => $attributes, 'excelChar' => $excelChar, 'not' => $not, 'name' => $name, 'objPHPExcel' => $objPHPExcel]);
 }