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


PHP Book::findOne方法代码示例

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


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

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

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

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

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

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

示例6: update

 public function update()
 {
     $this->preview = UploadedFile::getInstance($this, 'preview');
     if ($this->validate()) {
         $book = Book::findOne($this->book_id);
         $book->name = $this->name;
         $book->date = strtotime($this->date);
         $book->author_id = $this->author_id;
         $dir = Yii::getAlias(Yii::$app->params['previewPath']);
         $uploaded = false;
         if ($this->preview) {
             $filename = 'b' . $this->book_id . 'preview.' . $this->preview->extension;
             $uploaded = $this->preview->saveAs($dir . '/' . $filename);
             $img = Image::getImagine()->open($dir . '/' . $filename);
             $size = $img->getSize();
             $ratio = $size->getWidth() / $size->getHeight();
             $width = 700;
             $height = round($width / $ratio);
             Image::thumbnail($dir . '/' . $filename, $width, $height)->save($dir . '/' . $filename, ['quality' => 80]);
             $ratio = $size->getWidth() / $size->getHeight();
             $width = 200;
             $height = round($width / $ratio);
             Image::thumbnail($dir . '/' . $filename, $width, $height)->save($dir . '/th_' . $filename, ['quality' => 80]);
         } else {
             $filename = '';
         }
         if ($uploaded) {
             if (is_file(Yii::getAlias(Yii::$app->params['previewPath']) . '/' . $book->preview)) {
                 unlink(Yii::getAlias(Yii::$app->params['previewPath']) . '/' . $book->preview);
             }
             $book->preview = $filename;
         }
         $book->save();
         return $book;
     }
     return null;
 }
开发者ID:VasiliyBaranov,项目名称:tz,代码行数:37,代码来源:BookForm.php

示例7: actionViewAjax

 /**
  * View book.
  * @return mixed
  */
 public function actionViewAjax($id)
 {
     $this->layout = '/empty';
     $model = Book::findOne($id);
     return $this->render('view-ajax', ['model' => $model]);
 }
开发者ID:Godscreature,项目名称:Books,代码行数:10,代码来源:BookController.php

示例8: update

 /**
  * update book.
  * @return Book|null the saved model or null if saving fails
  */
 public function update()
 {
     // подтягиваем файлы перед валидацией, что бы все вместе проверять
     $this->preview = UploadedFile::getInstance($this, 'preview');
     if ($this->validate()) {
         $book = Book::findOne($this->book_id);
         $book->name = $this->name;
         $book->date = strtotime($this->date);
         $book->author_id = $this->author_id;
         // Дописываем файл
         $dir = Yii::getAlias(Yii::$app->params['previewPath']);
         $uploaded = false;
         if ($this->preview) {
             // если файл залился - пишем в базу данные по файлу
             $filename = 'b' . $this->book_id . 'preview.' . $this->preview->extension;
             $uploaded = $this->preview->saveAs($dir . '/' . $filename);
             // урезаем размер файла, что б не грущили 100500мегабайт и пересохраняем
             $img = Image::getImagine()->open($dir . '/' . $filename);
             $size = $img->getSize();
             $ratio = $size->getWidth() / $size->getHeight();
             $width = 700;
             $height = round($width / $ratio);
             Image::thumbnail($dir . '/' . $filename, $width, $height)->save($dir . '/' . $filename, ['quality' => 80]);
             // делаем превьюшку
             $ratio = $size->getWidth() / $size->getHeight();
             $width = 200;
             $height = round($width / $ratio);
             Image::thumbnail($dir . '/' . $filename, $width, $height)->save($dir . '/th_' . $filename, ['quality' => 80]);
         } else {
             $filename = '';
         }
         if ($uploaded) {
             // удалим старый файл, если он был
             if (is_file(Yii::getAlias(Yii::$app->params['previewPath']) . '/' . $book->preview)) {
                 unlink(Yii::getAlias(Yii::$app->params['previewPath']) . '/' . $book->preview);
             }
             $book->preview = $filename;
             // обновляем имя файла аватара
         }
         $book->save();
         return $book;
     }
     return null;
 }
开发者ID:Godscreature,项目名称:Books,代码行数:48,代码来源:BookForm.php

示例9: actionDelete

 public function actionDelete($id)
 {
     $product = Book::findOne($id);
     if (!empty($product)) {
         if (!empty($product->img)) {
             unlink('../uploads/' . $product->img);
         }
         $product->delete();
         $session = new Session();
         $session->open();
         $session->setFlash('message', 'Data Deleted.');
         return $this->redirect(['index']);
     }
 }
开发者ID:pichai2514,项目名称:gov_book2016,代码行数:14,代码来源:BookController.php

示例10: actionDelete

 /**
  * Удаление книги.
  *
  * @param int $id
  * @return \yii\web\Response
  */
 public function actionDelete($id)
 {
     /** @var Book $modelBook */
     $modelBook = Book::findOne($id);
     if ($modelBook->delete()) {
         return $this->redirect(['back-book/index']);
     }
     return $this->refresh();
 }
开发者ID:Rey8d01,项目名称:book-catalog,代码行数:15,代码来源:BackBookController.php

示例11: actionUpdate

 public function actionUpdate($id = NULL)
 {
     if ($id === NULL) {
         throw new HttpException(404, 'Not Found');
     }
     $model = Book::findOne($id);
     if ($model === NULL) {
         throw new HttpException(404, 'Document Does Not Exist');
     }
     if (isset($_POST['Book'])) {
         $model->name = $_POST['Book']['name'];
         $model->date_create = $_POST['Book']['date_create'];
         $model->date_update = $_POST['Book']['date_update'];
         $model->preview = $_POST['Book']['preview'];
         $model->date = $_POST['Book']['date'];
         $model->author_id = $_POST['Book']['author_id'];
         if ($model->save()) {
             return $this->redirect(['site/index']);
         }
     }
     echo $this->render('create', array('model' => $model));
 }
开发者ID:shaforostov,项目名称:yii2test,代码行数:22,代码来源:SiteController.php

示例12: actionView

 /**
  * Страница просмотра книги по ее уникальному псевдниму.
  *
  * @param string $alias
  * @return string
  */
 public function actionView($alias)
 {
     $modelBook = Book::findOne(['alias' => $alias]);
     return $this->render('view', ['modelBook' => $modelBook]);
 }
开发者ID:Rey8d01,项目名称:book-catalog,代码行数:11,代码来源:FrontController.php

示例13: getReservationFieldsProvider

 protected function getReservationFieldsProvider($id)
 {
     $book = \app\models\Book::findOne($id);
     $tourFields = \app\models\TourField::find()->where(['tour_id' => $book->tour_id])->orderBy('position')->all();
     $bookValues = \app\models\BookValue::find()->where(['book_id' => $book->id])->indexBy('tour_field_id')->all();
     //print '<pre>'; print_r($tourFields); die();
     foreach ($tourFields as $field) {
         $data[] = ['name' => $field->name, 'value' => array_key_exists($field->id, $bookValues) ? $bookValues[$field->id]->value : ''];
     }
     //print '<pre>'; print_r($data); die();
     $provider = new \yii\data\ArrayDataProvider(['allModels' => $data]);
     return $provider;
 }
开发者ID:ukrsolution,项目名称:booking_system,代码行数:13,代码来源:TourController.php

示例14: actionDelete

 public function actionDelete($id)
 {
     Book::findOne($id)->delete();
     return $this->goBack();
 }
开发者ID:hlogeon,项目名称:yii2-test,代码行数:5,代码来源:BookController.php


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