/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Gallery::find()->joinWith('galleryPhotos', false)->groupBy('g_gallery.gallery_id'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]); $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(['gallery_id' => $this->gallery_id, 'date' => $this->date]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'descr', $this->descr]); return $dataProvider; }
/** * Finds the Gallery model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Gallery the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Gallery::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('Страница не найдена.'); } }
public function getGallery() { return $this->hasOne(Gallery::className(), ['gallery_id' => 'gallery_id']); }