當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Book::save方法代碼示例

本文整理匯總了PHP中app\models\Book::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Book::save方法的具體用法?PHP Book::save怎麽用?PHP Book::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Book的用法示例。


在下文中一共展示了Book::save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionCreate

 public function actionCreate()
 {
     //echo Yii::$app->basePath;exit;
     $path = realpath(Yii::$app->basePath) . "/images/";
     //$path = "localhost/library_software/frontend/images/";
     $model = new Book();
     $model->attributes = Yii::$app->request->post()['book'];
     //print_r($model);exit;
     //echo Yii::$app->request->post()['book']['cat_id'];exit;
     $model->cat_id = implode(",", $model['cat_id']);
     //print_r($model);exit;
     $image = $_FILES['file']['name'];
     $ext = end(explode(".", $image));
     if ($ext == 'jpg' || $ext == 'png' || $ext == 'gif' || $ext == 'jpeg') {
         $filename = Yii::$app->security->generateRandomString() . ".{$ext}";
         $model->cover_photo = $filename;
         if ($model->save()) {
             move_uploaded_file($_FILES['file']['tmp_name'], $path . '/' . $filename);
             return ['error' => false, 'data' => $model];
         } else {
             return ['error' => true, 'data' => $model->errors];
         }
     } else {
         return ['error' => true, 'data' => ['photo' => 'File type not allowed.']];
     }
     /* print_r($_FILES);
     		print_r(Yii::$app->request->post()['book']);
     		exit; */
 }
開發者ID:engrashid,項目名稱:library,代碼行數:29,代碼來源:BookController.php

示例2: prosesAdd

 public function prosesAdd()
 {
     if ($this->petugas == null) {
         header("Location: " . base . "/Auth");
         exit;
     }
     $valid = new Validator($_POST);
     $valid->rule('required', ['title', 'author', 'publisher', 'category']);
     if ($valid->validate()) {
         $book = new Book();
         $book->BookTitle = $_POST['title'];
         $book->BookAuthor = $_POST['author'];
         $book->PublisherID = $_POST['publisher'];
         $book->CategoryID = $_POST['category'];
         $book->BookPageCount = $_POST['pageCount'];
         $book->BookPublished = $_POST['year'];
         $book->BookDescription = $_POST['des'];
         $book->BookPhoto = "acas";
         $book->BookDateAdd = Carbon::now();
         $book->BookPrice = $_POST['price'];
         if ($book->save()) {
             if ($_FILES['photo']['name'] != "") {
                 $uploaddir = '/var/www/limsmvc/img/';
                 $uploadfile = $uploaddir . $book->BookID;
                 move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile);
             }
         }
         header("Location: " . base . "/Book");
     } else {
         // Errors
         print_r($valid->errors());
     }
 }
開發者ID:blegoh,項目名稱:Web,代碼行數:33,代碼來源:BookController.php

示例3: actionCreate

 /**
  * Creates a new Book model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Book();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:tdimdimich,項目名稱:tt_yii2,代碼行數:14,代碼來源:BookController.php

示例4: actionCreate

 /**
  * Creates a new Book model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Book();
     $authors = \app\models\Author::find()->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'authors' => $authors]);
     }
 }
開發者ID:jerichozis,項目名稱:books,代碼行數:15,代碼來源:BookController.php

示例5: actionCreate

 public function actionCreate()
 {
     $book = new Book();
     if (Yii::$app->request->isPost) {
         $book->load(Yii::$app->request->post());
         $book->save();
         $this->redirect(Url::to(['books/index']));
     }
     return $this->render('create', ['book' => $book, 'authors' => Author::find()->all()]);
 }
開發者ID:k666r,項目名稱:test_yii2,代碼行數:10,代碼來源:BooksController.php

示例6: actionCreate

 /**
  * Creates a new Book model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Book();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         \yii\caching\TagDependency::invalidate(Yii::$app->cache, 'books');
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:scarneros,項目名稱:yii2-tutorial,代碼行數:15,代碼來源:BookController.php

示例7: runBookInsertion

 function runBookInsertion($i)
 {
     $book = new Book();
     $book->title = 'Hello' . $i;
     $book->isbn = '1234';
     $book->price = $i;
     //$book->author_id = $this->authors[array_rand($this->authors)]->id;
     $book->link('author', $this->authors[array_rand($this->authors)]);
     $book->save(false);
     $this->books[] = $book;
 }
開發者ID:motin,項目名稱:forked-php-orm-benchmark,代碼行數:11,代碼來源:Yii2MTestSuite.php

示例8: actionCreate

 /**
  * Creates a new Book model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Book();
     $searchModel = new BookSearch();
     $authors = $searchModel->getAuthors()->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'authors' => $authors]);
     }
 }
開發者ID:vasiakorobkin,項目名稱:yii2-testcase,代碼行數:16,代碼來源:BookController.php

示例9: actionCreate

 /**
  * Creates a new Book model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Book();
     $authors = Author::find()->asArray()->all();
     for ($i = 1; $i <= Author::find()->count(); $i++) {
         $authors_array[$i] = $authors[$i - 1]['firstname'] . ' ' . $authors[$i - 1]['lastname'];
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'authors_array' => $authors_array]);
     }
 }
開發者ID:snedi,項目名稱:musical-broccoli,代碼行數:18,代碼來源:BookController.php

示例10: addAction

 /**
  * @Post("/")
  *
  * @return Response
  */
 public function addAction()
 {
     $bookData = $this->request->getJsonRawBody();
     $book = new Book();
     $book->setName($bookData->name);
     $book->setDescription($bookData->description);
     $response = new Response();
     if ($book->save() === true) {
         $response->setStatusCode(201, "Created");
         $response->setJsonContent(['status' => 'OK', 'data' => $book->getId()]);
     } else {
         $this->createErrorResponse($response, $book);
     }
     return $response;
 }
開發者ID:vladylen,項目名稱:phalcon,代碼行數:20,代碼來源:BooksController.php

示例11: insert

 /**
  * create book.
  * @return Book|null the saved model or null if saving fails
  */
 public function insert()
 {
     $this->preview = UploadedFile::getInstance($this, 'preview');
     if ($this->validate()) {
         $book = new Book();
         $book->name = $this->name;
         $book->date = strtotime($this->date);
         $book->author_id = $this->author_id;
         if ($book->save()) {
             // если сохранило сообщение, то дописываем файл ------------------------------
             $dir = Yii::getAlias(Yii::$app->params['previewPath']);
             // если надо - создаем каталог
             if (!is_dir($dir)) {
                 BaseFileHelper::createDirectory($dir, 0777);
             }
             $uploaded = false;
             $filename = '';
             if ($this->preview) {
                 $filename = 'b' . $book->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]);
             }
             // если файл залился - пишем в базу данные по файлу
             if ($uploaded) {
                 $bookData = Book::findOne($book->book_id);
                 $bookData->preview = $filename;
                 $bookData->save();
             }
             return $book;
         }
     }
     return null;
 }
開發者ID:Godscreature,項目名稱:Books,代碼行數:48,代碼來源:BookForm.php

示例12: save

 /**
  * @param Book $model
  * @param $template
  * @return array|Response
  */
 protected function save($model, $template)
 {
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->save(false)) {
                 $params = ArrayHelper::merge(['index'], $this->getSession()->get(self::SESSION_PARAMS));
                 return $this->redirect($params);
             } else {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 return ActiveForm::validate($model);
             }
         } else {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     } else {
         return $this->{$this->getCurrentRender()}($template, ['model' => $model, 'authors' => $this->getAuthors()]);
     }
 }
開發者ID:vitalik74,項目名稱:gosman-test-app,代碼行數:24,代碼來源:BookController.php

示例13: actionCreate

 /**
  * Creates a new Book model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Book();
     if (!empty(Yii::$app->request->post())) {
         $model->setAttributes(Yii::$app->request->post());
         $model->authors = Yii::$app->request->post('authors');
         $model->tags = Yii::$app->request->post('tags');
         $model->formats = Yii::$app->request->post('formats');
         if ($model->save()) {
             $bookFiles = \Yii::$app->basePath . '/files/tmp/book-form/1/';
             $imgFile = \Yii::$app->basePath . '/web/image/book/tmp/1/';
             $this->copyFiles($bookFiles, \Yii::$app->basePath . '/files/books/' . $model->id . '/');
             $this->copyFiles($imgFile, \Yii::$app->basePath . '/web/image/book/' . $model->id . '/');
             $this->deleteFiles(\Yii::$app->basePath . '/files/tmp/book-form/1/');
             $this->deleteFiles(\Yii::$app->basePath . '/web/image/book/tmp/1/');
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:CrystalEller,項目名稱:yii2ebooks,代碼行數:25,代碼來源:BookController.php

示例14: actionCreate

 /**
  * Creates a new Book model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Book();
     $time = time();
     $model->date_create = date('Y-m-d H:i:s', $time);
     $authorData = Author::find()->all();
     $authorsList = [];
     foreach ($authorData as $author) {
         $authorsList[$author->id] = $author->firstname . ' ' . $author->lastname;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($model->preview = UploadedFile::getInstance($model, 'preview')) {
             $path = Yii::$app->basePath . Yii::$app->params['uploadPath'] . $model->preview;
             $model->preview->saveAs($path);
             $model->preview = Yii::$app->params['uploadPath'] . $model->preview;
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'authors' => $authorsList]);
     }
 }
開發者ID:ElegguaDP,項目名稱:books,代碼行數:27,代碼來源:BookController.php

示例15: insert

 public function insert()
 {
     $this->preview = UploadedFile::getInstance($this, 'preview');
     if ($this->validate()) {
         $book = new Book();
         $book->name = $this->name;
         $book->date = strtotime($this->date);
         $book->author_id = $this->author_id;
         if ($book->save()) {
             $dir = Yii::getAlias(Yii::$app->params['previewPath']);
             if (!is_dir($dir)) {
                 BaseFileHelper::createDirectory($dir, 0777);
             }
             $uploaded = false;
             $filename = '';
             if ($this->preview) {
                 $filename = 'b' . $book->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]);
             }
             if ($uploaded) {
                 $bookData = Book::findOne($book->book_id);
                 $bookData->preview = $filename;
                 $bookData->save();
             }
             return $book;
         }
     }
     return null;
 }
開發者ID:VasiliyBaranov,項目名稱:tz,代碼行數:39,代碼來源:BookForm.php


注:本文中的app\models\Book::save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。