當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。