/** * Логика поиска * @param $params * @return ActiveDataProvider */ public function search($params) { $query = Author::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => self::PAGE_SIZE]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname]); return $dataProvider; }
public function getAuthor() { return $this->hasOne(Author::className(), ['id' => 'author_id']); }
/** * Finds the Author model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Author the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Author::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Метод получения всех авторов * @return array */ protected function getAuthors() { /** @var Author[] $models */ $models = Author::find()->all(); $records = []; if ($models) { foreach ($models as $model) { $records[$model->id] = $model->getFullName(); } } return $records; }