/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Photos::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, 'album_id' => $this->album_id]); $query->andFilterWhere(['like', 'filename', $this->filename])->andFilterWhere(['like', 'caption', $this->caption])->andFilterWhere(['like', 'alt_text', $this->alt_text]); return $dataProvider; }
/** * Finds the Photos model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Photos the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Photos::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Displays a single Album model. * @param integer $id * @return mixed */ public function actionView($id) { $dataProvider = new ActiveDataProvider(['query' => Photos::find()->where(['album_id' => '' . $id])]); return $this->render('view', ['model' => $this->findModel($id), 'dataProvider' => $dataProvider]); }
/** * @return \yii\db\ActiveQuery */ public function getPhotos() { return $this->hasMany(Photos::className(), ['album_id' => 'id']); }