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


PHP models\Book类代码示例

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


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

示例1: searchISBN

 public function searchISBN()
 {
     if (\Request::ajax()) {
         $data = array();
         $isbn = \Input::get('isbn');
         if (is_numeric($isbn)) {
             $book = Book::where('isbn', $isbn)->first();
             if ($book) {
                 $product = \Auth::user()->organization->products->find($book->id);
                 if ($product) {
                     // το βιβλίο υπάρχει στον οργανισμό και μπορούμε να το κάνουμε μόνο EDIT
                     $data['find'] = true;
                     $data['id'] = $book->id;
                     $data['title'] = $book->product->title;
                     $data['barcode'] = $book->product->barcode;
                     $data['notify'] = '<p>Το βιβλίο με το συγκεκριμένο ISBN <strong> υπάρχει ήδη. </strong> </p> <p>Μπορείτε να το τροποποιήσετε κάνοντας κλικ στον τίτλο:</p>';
                 } else {
                     // το βιβλίο υπάρχει σε άλλον οργανισμό και μπορούμε να το προσθέσουμε μόνο ως item
                     $data['find'] = true;
                     $data['external'] = true;
                     $data['id'] = $book->id;
                     $data['title'] = $book->product->title;
                     $data['barcode'] = $book->product->barcode;
                     $data['notify'] = '<p>Το βιβλίο με το συγκεκριμένο ISBN είναι καταχωρημένο από άλλο οργανισμό. Θέλετε να το προσθέσετε?</p>';
                 }
             }
             // else σημαίνει ότι όλα ΟΚ για create_book
         }
         return $data;
     }
     // END If
 }
开发者ID:nicsmyrn,项目名称:library,代码行数:32,代码来源:AjaxBookRepository.php

示例2: 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

示例3: 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

示例4: actionForm

 public function actionForm($book_id)
 {
     $product = Book::findOne($book_id);
     $productImage = new BookImage();
     if (!empty($_FILES['BookImage'])) {
         $img = $_FILES['BookImage']['name']['url'];
         $ext = end(explode(".", $img));
         $name = microtime();
         $name = str_replace(' ', '', $name);
         $name = str_replace('.', '', $name);
         $name = $name . '.' . $ext;
         $tmp = $_FILES['BookImage']['tmp_name']['url'];
         $productImage->url = $name;
         move_uploaded_file($tmp, '../uploads/' . $name);
     }
     if (!empty($_POST)) {
         $productImage->name = $_POST['BookImage']['name'];
         $productImage->product_id = $book_id;
         if ($productImage->save()) {
             $session = new Session();
             $session->open();
             $session->setFlash('message', 'Data Saved.');
             return $this->redirect(['index', 'book_id' => $book_id]);
         }
     }
     return $this->render('//BookImage/Form', ['product' => $product, 'productImage' => $productImage]);
 }
开发者ID:pichai2514,项目名称:gov_book2016,代码行数:27,代码来源:BookImageController.php

示例5: loadModel

 /**
  * @param $id
  * @return null|Book
  * @throws NotFoundHttpException
  */
 private function loadModel($id)
 {
     $model = Book::findOne($id);
     if (null == $model) {
         throw new NotFoundHttpException('Книга не найдена');
     }
     return $model;
 }
开发者ID:dub34,项目名称:books-test,代码行数:13,代码来源:BooksController.php

示例6: 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

示例7: bookItemWithTransformer

 public function bookItemWithTransformer()
 {
     $fractal = new Manager();
     $book = Book::all()->random(1);
     //$book = Book::find(1);
     $resource = new Item($book, new BookTransformer());
     return $fractal->createData($resource)->toJson();
 }
开发者ID:kongtoonarmy,项目名称:laravel-transformers,代码行数:8,代码来源:BookController.php

示例8: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('books')->truncate();
     $faker = \Faker\Factory::create();
     for ($count = 0; $count < 500; $count++) {
         Book::create(['title' => $faker->sentence(), 'desc' => $faker->text(), 'cover' => $faker->imageUrl()]);
     }
 }
开发者ID:aphiwadChhoeun,项目名称:Book-API,代码行数:13,代码来源:BookTableSeeder.php

示例9: actionDelete

 public function actionDelete($id)
 {
     $book = Book::findOne(['id' => $id]);
     if ($book) {
         $book->delete();
     }
     $this->redirect(Url::to(['books/index']));
 }
开发者ID:k666r,项目名称:test_yii2,代码行数:8,代码来源:BooksController.php

示例10: findModel

 protected function findModel($id)
 {
     if (($model = Book::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:vagrant200192,项目名称:traning,代码行数:8,代码来源:BookController.php

示例11: 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

示例12: actionDelete

 public function actionDelete()
 {
     $id = (int) Yii::$app->request->get('id');
     /** @var Book $book */
     $book = Book::findOne(['id' => $id]);
     $result = $book ? $book->delete() : false;
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['result' => (bool) $result];
 }
开发者ID:sedpro,项目名称:yii2-test-app,代码行数:9,代码来源:BookController.php

示例13: 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

示例14: 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

示例15: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     Book::truncate();
     $faker = Faker::create();
     for ($i = 1; $i <= 30; $i++) {
         Book::create(['title' => $faker->sentence(), 'description' => $faker->sentence(), 'author' => $faker->name]);
     }
 }
开发者ID:kongtoonarmy,项目名称:laravel-transformers,代码行数:15,代码来源:BooksTableSeeder.php


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