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


PHP Book::load方法代碼示例

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


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

示例1: 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();
     $returning = function () use($model) {
         $authors = Author::find()->all();
         $dropDownSearchItems = ArrayHelper::map($authors, 'id', 'lastname');
         return $this->render('create', ['model' => $model, 'dropDownAuthorItems' => $dropDownSearchItems]);
     };
     if ($model->load(Yii::$app->request->post())) {
         $model->image = UploadedFile::getInstance($model, 'image');
         if (is_object($model->image)) {
             $preview = 'preview_img/' . uniqid() . '_' . $model->image->name;
             $model->image->saveAs($preview);
             $model->image = null;
             $model->preview = '/' . $preview;
         }
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $returning();
         }
     } else {
         return $returning();
     }
 }
開發者ID:AlexanderKosianchuk,項目名稱:bookItemsRoll,代碼行數:30,代碼來源:BookController.php

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

示例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();
     $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

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

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

示例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->previewFile = UploadedFile::getInstance($model, 'previewFile');
         if ($model->upload() && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:asmsoft,項目名稱:books,代碼行數:16,代碼來源:BookController.php

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

示例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();
     if ($model->load(Yii::$app->request->post())) {
         $file = UploadedFile::getInstance($model, 'preview');
         if ($model->upload($file) && $model->save()) {
             return $this->redirect(Url::previous());
         }
     }
     return $this->render('create', ['model' => $model, 'authors' => Author::find()->all()]);
 }
開發者ID:AndreyLipin,項目名稱:testing,代碼行數: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();
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         $model->imageFile = UploadedFile::getInstance($model, 'preview');
         $model->uploadFile();
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'authors' => (new AuthorCollection())->createEntity(Author::find()->all(), true)]);
     }
 }
開發者ID:GotFly,項目名稱:books,代碼行數:18,代碼來源:BookController.php

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

示例11: 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->bookImage = UploadedFile::getInstance($model, 'bookImage');
         if ($model->validate() && $model->save()) {
             if (Url::previous()) {
                 return $this->redirect(Url::previous());
             }
             return $this->redirect(Url::toRoute('index'));
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:RuAnDe,項目名稱:yii2_books_example,代碼行數:19,代碼來源:BooksController.php

示例12: 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())) {
         $image = UploadedFile::getInstance($model, 'preview');
         $temp_var = explode(".", $image->name);
         $ext = end($temp_var);
         $model->date = Book::getIntDate($model->date);
         $model->preview = Yii::$app->security->generateRandomString() . ".{$ext}";
         $path = Yii::$app->params['uploadPath'] . $model->preview;
         $image->saveAs($path);
         $model->save();
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'author' => Author::find()->all()]);
     }
 }
開發者ID:kostik34,項目名稱:tz.php,代碼行數:22,代碼來源: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 ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $image = UploadedFile::getInstance($model, 'imageFile');
         if (!empty($image)) {
             $model->image = Yii::$app->security->generateRandomString() . '.' . $image->extension;
             $path = Yii::$app->basePath . '/' . Book::IMAGES_DIRECTORY . $model->image;
             $model->save();
             $image->saveAs($path);
         } else {
             $model->save();
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:kmolchanov,項目名稱:rgkgroup-test,代碼行數:23,代碼來源:BookController.php

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

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


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