当前位置: 首页>>代码示例>>PHP>>正文


PHP Books::find方法代码示例

本文整理汇总了PHP中app\models\Books::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::find方法的具体用法?PHP Books::find怎么用?PHP Books::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Books的用法示例。


在下文中一共展示了Books::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionIndex

 /**
  * Lists all Books models.
  * @return mixed
  */
 public function actionIndex()
 {
     //Yii::$app->user->isGuest;
     $authors = Authors::find()->all();
     $get = Yii::$app->request->get()['Filter'];
     $dataProvider;
     $query = Books::find();
     if (isset(Yii::$app->request->get()['Filter'])) {
         if ($get["author_id"] != 0) {
             $query->andWhere(['author_id' => $get["author_id"]]);
         }
         if ($get["title"] != "") {
             //$query->andWhere(['name' => $post["title"]]);
             $query->andWhere(['like', 'name', $get["title"]]);
         }
         if ($get["dateMin"] != "") {
             $query->andWhere('date > :dateMin', [':dateMin' => $get["dateMin"]]);
         }
         if ($get["dateMax"] != "") {
             $query->andWhere('date < :dateMax', [':dateMax' => $get["dateMax"]]);
         }
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'authors' => $authors]);
 }
开发者ID:Kakiho,项目名称:testtask,代码行数:29,代码来源:BooksController.php

示例2: search

 public function search($params)
 {
     Yii::$app->session['BooksSearch'] = $params;
     $query = Books::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]);
     $dataProvider->setSort(['attributes' => ['id', 'name', 'preview', 'authorfullname' => ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lasttname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lasttname' => SORT_DESC], 'label' => Yii::t('app', 'Author'), 'default' => SORT_ASC], 'date', 'date_create']]);
     $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');
         $query->joinWith(['author']);
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name]);
     if ($this->date_from) {
         $query->andFilterWhere(['>=', 'date', $this->date_from]);
     }
     if ($this->date_to) {
         $query->andFilterWhere(['<=', 'date', $this->date_to]);
     }
     if ($this->author_id) {
         $query->andFilterWhere(['author_id' => $this->author_id]);
     }
     $query->joinWith(['author']);
     return $dataProvider;
 }
开发者ID:akomyagin,项目名称:books,代码行数:26,代码来源:BooksSearch.php

示例3: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::find()->with('authors');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'name', 'authorFullName' => ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lastname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lastname' => SORT_DESC], 'label' => 'Автор'], 'date_update', 'date_create', 'date']]);
     $this->load($params);
     // валидация
     if (!$this->validate()) {
         $query->joinWith(['authors']);
         return $dataProvider;
     }
     // Фильтр по Автору
     $query->joinWith(['authors' => function ($q) {
         $this->authorFullName = trim($this->authorFullName);
         if ($this->authorFullName) {
             $Asearch = str_replace(" ", "|", $this->authorFullName);
             $q->where('`authors`.`firstname` RLIKE "' . $Asearch . '" ' . 'OR `authors`.`lastname` RLIKE "' . $Asearch . '"');
         }
     }]);
     /*  $query->andFilterWhere([
             'name' => $this->name,
             'authors.firstname' => $this->authorFullName,
         ]);*/
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['BETWEEN', 'date', $this->date_1, $this->date_2]);
     return $dataProvider;
 }
开发者ID:pmesher,项目名称:taskmy,代码行数:33,代码来源:BooksSearch.php

示例4: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::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;
     }
     if ($this->author_id) {
         $query->andFilterWhere(['author_id' => $this->author_id]);
     }
     if ($this->date_from) {
         if ($this->date_till) {
             $query->andFilterWhere(['date' => ['between', $this->date_from, $this->date_till]]);
         } else {
             $query->andFilterWhere(['>=', 'date', $this->date_from]);
         }
     } elseif ($this->date_till) {
         $query->andFilterWhere(['<=', 'date', $this->date_till]);
     }
     if ($this->name) {
         $query->andFilterWhere(['like', 'name', $this->name]);
     }
     return $dataProvider;
 }
开发者ID:IuriiP,项目名称:test160107,代码行数:34,代码来源:BookSearch.php

示例5: actionIndex

 /**
  * Lists all Books models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new BooksSearch();
     //            $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider = new ActiveDataProvider(['query' => Books::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
 }
开发者ID:Cranky4,项目名称:books_test,代码行数:11,代码来源:BooksController.php

示例6: getSearchQuery

 /**
  * Get query for book search
  * @return [QueryInterface]
  */
 public function getSearchQuery()
 {
     $query = Books::find();
     //Author
     $query = $query->filterWhere(['author_id' => $this->author_id]);
     //Name
     if (!empty($this->name)) {
         $query = $query->andWhere(['like', 'name', $this->name]);
     }
     //Date
     if ($this->firstTimestamp != 0 && $this->secondTimestamp != 0) {
         if ($this->firstTimestamp == $this->secondTimestamp) {
             $query = $query->andWhere(['=', 'date', $this->firstTimestamp]);
         } else {
             $query = $query->andWhere(['between', 'date', $this->firstTimestamp, $this->secondTimestamp]);
         }
     } else {
         if ($this->firstTimestamp != 0) {
             $query = $query->andWhere(['>=', 'date', $this->firstTimestamp]);
         } else {
             if ($this->secondTimestamp != 0) {
                 $query = $query->andWhere(['<=', 'date', $this->secondTimestamp]);
             }
         }
     }
     return $query;
 }
开发者ID:Dr1N,项目名称:BooksOrganizer,代码行数:31,代码来源:SearchForm.php

示例7: actionRemove

 public function actionRemove($id)
 {
     if (Yii::$app->request->isAjax) {
         $model = Books::find()->where(['id' => $id])->one();
         $model->delete();
         Yii::$app->response->format = Response::FORMAT_JSON;
         return array('result' => true);
     }
     return $this->redirect('index.php?r=site%2Fbooks');
 }
开发者ID:mustymenko,项目名称:yii-test,代码行数:10,代码来源:BooksController.php

示例8: actionIndex

 public function actionIndex($order = false, $order_type = false, $search_key = false)
 {
     $order_field = $order ? $order : 'id';
     $order_type = $order_type ? $order_type == 'DESC' ? SORT_DESC : SORT_ASC : SORT_ASC;
     if ($search_key) {
         $query = Books::find()->andFilterWhere(['or', ['like', 'author', $search_key], ['like', 'name', $search_key]]);
     } else {
         $query = Books::find();
     }
     return new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => [$order_field => $order_type]]]);
 }
开发者ID:cutcut,项目名称:orbitsoft,代码行数:11,代码来源:BooksController.php

示例9: getAuthorBooks

 public static function getAuthorBooks($author_id, $return_count = true)
 {
     $author_id = (int) $author_id;
     $data = Books::find()->where('authors LIKE "%,' . $author_id . '" OR authors LIKE "%' . $author_id . '," OR authors LIKE "' . $author_id . '"');
     if ($return_count) {
         $data = (int) $data->count();
     } else {
         $data = $data->all();
     }
     return $data;
 }
开发者ID:Diakonrus,项目名称:test_zadanie_2,代码行数:11,代码来源:BooksAuthors.php

示例10: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::find()->addSelect([$this->tableName() . ".*", "CONCAT(authors.firstname, ' ', authors.lastname) AS author_fullname"])->joinWith(['author']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['author'] = ['asc' => ['authors.firstname' => SORT_ASC], 'desc' => ['authors.firstname' => 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(['like', 'books.name', $this->name]);
     // поиск по дате от/до
     if (!empty($this->book_date_from) and !empty($this->book_date_to)) {
         // конвертирую в корректный формат времени и добавляю четкие временные границы
         $book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->book_date_from), 'dd-MM-yyyy 00:00:00');
         $book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->book_date_to), 'dd-MM-yyyy 23:59:59');
         $book_date_from = Yii::$app->formatter->asTimestamp($book_date_from);
         $book_date_to = Yii::$app->formatter->asTimestamp($book_date_to);
         $query->andFilterWhere(['between', 'books.date', $book_date_from, $book_date_to]);
     }
     // поиск по автору
     if ($this->author_fullname == 7 or in_array(trim(mb_strtolower($this->author)), array('без', 'без привязки', 'без привязки к автору'))) {
         // для книг без привязки к автору - из books
         $query->andFilterWhere(['=', 'author_id', 0]);
     } else {
         // из authors
         $query->andFilterWhere(['like', 'authors.firstname', $this->author]);
         $query->andFilterWhere(['=', 'authors.id', $this->author_fullname]);
     }
     /////////////////////// доп параметры для filterModel (если раскомменчены filterModel и Pjax в books/index.php)
     $query->andFilterWhere(['=', 'books.id', $this->id])->andFilterWhere(['like', 'books.preview', $this->preview]);
     // дата Выхода книги
     if (!empty($this->date)) {
         // конвертирую в корректный формат времени и добавляю четкие временные границы
         $book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date), 'dd-MM-yyyy 00:00:00');
         $book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date), 'dd-MM-yyyy 23:59:59');
         $book_date_from = Yii::$app->formatter->asTimestamp($book_date_from);
         $book_date_to = Yii::$app->formatter->asTimestamp($book_date_to);
         $query->andFilterWhere(['between', 'books.date', $book_date_from, $book_date_to]);
     }
     // дата Добавления книги
     if (!empty($this->date_create)) {
         // конвертирую в корректный формат времени и добавляю четкие временные границы
         $book_date_from = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date_create), 'dd-MM-yyyy 00:00:00');
         $book_date_to = Yii::$app->formatter->asDatetime(str_replace("/", "-", $this->date_create), 'dd-MM-yyyy 23:59:59');
         $book_date_from = Yii::$app->formatter->asTimestamp($book_date_from);
         $book_date_to = Yii::$app->formatter->asTimestamp($book_date_to);
         $query->andFilterWhere(['between', 'books.date_create', $book_date_from, $book_date_to]);
     }
     ///////////////////
     return $dataProvider;
 }
开发者ID:krausweb,项目名称:yiibooks,代码行数:61,代码来源:BooksSearch.php

示例11: search

 public function search($params)
 {
     $query = Books::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['author_id' => $this->author_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['<=', 'date', $this->date_to])->andFilterWhere(['>=', 'date', $this->date_from]);
     return $dataProvider;
 }
开发者ID:abegalinov,项目名称:test_task1,代码行数:12,代码来源:BooksSearch.php

示例12: dashboard

 public function dashboard()
 {
     // Check Author authentication Session
     if (!Auth::check('default')) {
         return $this->redirect('Authors::login');
     }
     // Retrieve current Author ID
     $author_id = Auth::check('default')->data['id'];
     // Retrieve Books from the current Author
     $conditions = array('Books.author_id' => Auth::check('default')->data['id']);
     $books = Books::find('all', compact('conditions'));
     return compact('books', 'author_id');
 }
开发者ID:nicolasramy,项目名称:Book-Community,代码行数:13,代码来源:AuthorsController.php

示例13: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::find()->joinWith('bookAuthors')->asArray();
     $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]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'issue_year', $this->issue_year])->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'annotation', $this->annotation]);
     return $dataProvider;
 }
开发者ID:snedi,项目名称:book-management,代码行数:21,代码来源:BooksSearch.php

示例14: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::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, 'author_id' => $this->author_id != 0 ? $this->author_id : ''])->andFilterWhere(['between', 'date', $this->date_start, $this->date_end]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]);
     return $dataProvider;
 }
开发者ID:ustkirill,项目名称:test2,代码行数:21,代码来源:BooksSearch.php

示例15: delete

 public function delete()
 {
     // Check Author authentication Session
     if (!Auth::check('default')) {
         return $this->redirect('Authors::login');
     }
     $book = Books::find($this->request->id);
     if ($book && $book->delete()) {
         Session::write('message', 'Book deleted');
         $this->redirect(array('Authors::dashboard'));
     } else {
         Session::write('message', 'Book can not be deleted');
     }
 }
开发者ID:nicolasramy,项目名称:Book-Community,代码行数:14,代码来源:BooksController.php


注:本文中的app\models\Books::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。