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


PHP Book::find方法代码示例

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


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

示例1: search

 /**
  * Creates data provider instance with search query applied
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Book::find();
     $query->joinWith('author');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $dataProvider->sort->attributes['author.name'] = ['asc' => ['{{%author.name}}' => SORT_ASC], 'desc' => ['{{%author.name}}' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->author_id) {
         $query->andFilterWhere(['{{%book.author_id}}' => $this->author_id]);
     }
     if ($this->name) {
         $query->andFilterWhere(['like', '{{%book.name}}', $this->name]);
     }
     if ($this->date_from) {
         $query->andWhere('{{%book.date}} > :date_from', ['date_from' => strtotime($this->date_from)]);
     }
     if ($this->date_to) {
         $query->andWhere('{{%book.date}} < :date_to', ['date_to' => strtotime($this->date_to)]);
     }
     //        $query
     //            ->andFilterWhere(['{{%book.author_id}}' => $this->author_id])
     //            ->andFilterWhere(['like', '{{%book.name}}', $this->name])
     //            ->andWhere('{{%book.date}} > :date_from', ['date_from' => strtotime($this->date_from)])
     //            ->andWhere('{{%book.date}} < :date_to', ['date_to' => strtotime($this->date_to)]);
     return $dataProvider;
 }
开发者ID:Godscreature,项目名称:Books,代码行数:33,代码来源:BookSearch.php

示例2: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Book::find($id)->delete();
     \Session::flash('flash_message', 'Deleted Successfully!');
     \Session::flash('flash_message_level', 'success');
     return Redirect::back();
 }
开发者ID:razikallayi,项目名称:peaceschools,代码行数:13,代码来源:LibraryController.php

示例3: actionUpdate

 /**
  * Страница изменения информации книги.
  *
  * @param int $id
  * @return string|\yii\web\Response
  */
 public function actionUpdate($id)
 {
     /** @var Book $modelBook */
     $modelBook = Book::find()->with(['authors', 'tags'])->where(['id' => $id])->one();
     $this->_saveBook($modelBook);
     return $this->render('/back/book/update', ['modelBook' => $modelBook]);
 }
开发者ID:Rey8d01,项目名称:book-catalog,代码行数:13,代码来源:BackBookController.php

示例4: loadModel

 private function loadModel($id)
 {
     $model = Book::find($id)->one();
     if (!$model) {
         throw new HttpException(404, 'Not Found');
     }
     return $model;
 }
开发者ID:virtyos,项目名称:books_manager,代码行数:8,代码来源:SiteController.php

示例5: runJoinSearch

 public function runJoinSearch($i)
 {
     $book = \app\models\Book::find()->from('Book b')->with('author')->where('b.title = ?', ['Hello' . $i])->limit(1)->scalar();
     //        $book = $this->em->createQuery(
     //            'SELECT b, a FROM Book b JOIN b.author a WHERE b.title = ?1'
     //        )->setParameter(1, 'Hello' . $i)
     //         ->setMaxResults(1)
     //         ->getScalarResult();
 }
开发者ID:motin,项目名称:forked-php-orm-benchmark,代码行数:9,代码来源:YiiMScalarHydrateTestSuite.php

示例6: coverStore

 public function coverStore(Request $request, $id)
 {
     $book = Book::find($id);
     if (Gate::denies('manageBook', $book)) {
         abort(403, 'voce não é o dono desse livro');
     }
     $bookService = app()->make(BookService::class);
     $bookService->storeCover($book, $request->file('file'));
 }
开发者ID:phelipperibeiro,项目名称:book_store_laravel,代码行数:9,代码来源:BooksController.php

示例7: runJoinSearch

 public function runJoinSearch($i)
 {
     $book = Book::find()->from('Book b')->with('author')->where('b.title = :t', [':t' => 'Hello' . $i])->one();
     //        $book = $this->em->createQuery(
     //            'SELECT b, a FROM Book b JOIN b.author a WHERE b.title = ?1'
     //        )->setParameter(1, 'Hello' . $i)
     //         ->setMaxResults(1)
     //         ->getResult();
 }
开发者ID:motin,项目名称:forked-php-orm-benchmark,代码行数:9,代码来源:Yii2MTestSuite.php

示例8: searchAction

 /**
  * @Get("/search/{name}")
  *
  * @param $name
  *
  * @return Response
  */
 public function searchAction($name)
 {
     /** @var Book[] $books */
     $books = Book::find(["name LIKE '%{$name}%'"]);
     $response = new Response();
     $data = [];
     foreach ($books as $book) {
         $data[] = ['id' => $book->getId(), 'name' => $book->getName()];
     }
     return $response->setJsonContent($data);
 }
开发者ID:vladylen,项目名称:phalcon,代码行数:18,代码来源:BooksController.php

示例9: actionIndex

 public function actionIndex()
 {
     $dataProvider = new ArrayDataProvider(['allModels' => Book::find()->orderBy('rank')->limit(3)->asArray()->all()]);
     //$test = Book::getDb()->cache(function($db){
     //    Book::find()->orderBy('rank');
     //});
     //$result = $db->cache(function ($db) {
     //    return $db->createCommand('SELECT * FROM user WHERE id=4')->queryOne();
     //});
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
开发者ID:scarneros,项目名称:yii2-tutorial,代码行数:11,代码来源:SiteController.php

示例10: downloadSample

 /**
  * Download book by id.
  *
  * @return Response
  */
 public function downloadSample($idbook)
 {
     $fileBooks = Book::find($idbook)->filebooks()->where('is_sample', 1)->get();
     if (count($fileBooks) >= 1) {
         $files = array();
         foreach ($fileBooks as $key => $value) {
             array_push($files, base_path() . '/book/' . $idbook . '/' . $value->link);
         }
         Zipper::make(base_path() . '/book/' . $idbook . '/sample.zip')->add($files);
     }
     $pathDownload = base_path() . "/book/" . $idbook . '/sample.zip';
     return response()->download($pathDownload);
 }
开发者ID:phanngoc,项目名称:elearnpub,代码行数:18,代码来源:DetailBookController.php

示例11: actionIndex

 public function actionIndex()
 {
     $books = Book::find()->all();
     $data = array();
     foreach ($books as $book) {
         $dataBook = array();
         $dataBook['label'] = substr($book->name, 0, strpos($book->name, ':'));
         $listChapter = Chapter::find()->where(['book_id' => $book->id])->all();
         $dataBook['content'] = $this->renderPartial('list', ['book' => $book, 'listChapter' => $listChapter]);
         $data[] = $dataBook;
     }
     return $this->render('index', ['data' => $data]);
 }
开发者ID:vipnd2003,项目名称:trachthienky,代码行数:13,代码来源:SiteController.php

示例12: search

 public function search()
 {
     $query = Book::find();
     $this->addCondition($query, 'title', true);
     $this->addCondition($query, 'author_id');
     if ($this->date_created_from) {
         $query->andWhere(['>=', 'date_created', $this->date_created_from]);
     }
     if ($this->date_created_to) {
         $query->andWhere(['<=', 'date_created', $this->date_created_to]);
     }
     return new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]);
 }
开发者ID:k666r,项目名称:test_yii2,代码行数:13,代码来源:Book.php

示例13: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Book::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->joinWith(['author']);
     $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(['>', 'date', $this->published_from])->andFilterWhere(['<', 'date', $this->published_to])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['=', 'author_id', $this->author_id]);
     return $dataProvider;
 }
开发者ID:AlexanderKosianchuk,项目名称:bookItemsRoll,代码行数:21,代码来源:BookSearch.php

示例14: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Book::find()->joinWith('author')->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, 'date_update' => $this->date_update, 'date_create' => $this->date_create, 'date' => $this->date, 'author_id' => $this->author_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview]);
     return $dataProvider;
 }
开发者ID:snedi,项目名称:musical-broccoli,代码行数:21,代码来源:BookSearch.php

示例15: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Book::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, 'published_date' => $this->published_date]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
开发者ID:uaman89,项目名称:library,代码行数:21,代码来源:SearchBook.php


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