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