当前位置: 首页>>代码示例>>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;未经允许,请勿转载。