/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Announce::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSize'], 'pageParam' => 'page']]);
     $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->where("status != -1");
     $query->andFilterWhere(['id' => $this->id, 'start_time' => $this->start_time, 'end_time' => $this->end_time, 'modtime' => $this->modtime, 'createtime' => $this->createtime]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'keyword', $this->keyword]);
     if ($this->query_start) {
         $query->andWhere("start_time >= :starttime")->addParams([":starttime" => strtotime($this->query_start)]);
     } else {
         $this->query_start = null;
     }
     if ($this->query_end) {
         $query->andWhere("end_time <= :endtime")->addParams([":endtime" => strtotime($this->query_end)]);
     } else {
         $this->query_end = null;
     }
     if ($this->isAvailable) {
         $query->andWhere("start_time <= :time AND end_time >= :time")->addParams([":time" => time()]);
     }
     return $dataProvider;
 }
 private function loadModel($id)
 {
     $model = \common\models\entities\Announce::findOne(["id" => $id, "status" => 1]);
     if (!$model) {
         throw new yii\web\NotFoundHttpException('很抱歉查無資料');
     }
     return $model;
 }
 /**
  * Finds the Announce model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Announce the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Announce::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.', $this->errorLayout);
     }
 }