Ejemplo n.º 1
0
 public function search()
 {
     $params = $this->getData();
     $query = BooksModel::find();
     $query->joinWith(['author']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 2]]);
     $dataProvider->sort->attributes['author'] = ['asc' => ['author.firstname' => SORT_ASC], 'desc' => ['author.firstname' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'books.name', $this->name]);
     $fromTime = $this->from ? strtotime($this->from) : null;
     $toTime = $this->to ? strtotime($this->to) : null;
     $from = $fromTime ? date('Y-m-d h:i:s', $fromTime) : null;
     $to = $toTime ? date('Y-m-d h:i:s', $toTime) : null;
     $query->andFilterWhere(['between', 'books.date', $from, $to]);
     $query->andFilterWhere(['author.id' => $this->author]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 /**
  * Finds the BooksModel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return BooksModel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BooksModel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }