コード例 #1
0
ファイル: AuthorSearch.php プロジェクト: kocapb/library
 /**
  * Логика поиска
  * @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;
 }
コード例 #2
0
ファイル: Book.php プロジェクト: soanni/bookshelf
 public function getAuthor()
 {
     return $this->hasOne(Author::className(), ['id' => 'author_id']);
 }
コード例 #3
0
ファイル: AuthorController.php プロジェクト: kocapb/library
 /**
  * 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.');
     }
 }
コード例 #4
0
ファイル: BookController.php プロジェクト: kocapb/library
 /**
  * Метод получения всех авторов
  * @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;
 }