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


PHP Books::load方法代码示例

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


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

示例1: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->isGuest) {
         Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-danger'], 'body' => Yii::t('app', 'You are not authorized for this action.')]);
         return $this->redirect(Url::toRoute('/site/login'));
     }
     $model = new Books();
     if ($model->load(Yii::$app->request->post())) {
         $image = UploadedFile::getInstance($model, 'preview');
         if (!empty($image)) {
             $dir = Yii::getAlias('@app/web/img');
             $uploaded = $image->saveAs($dir . '/' . $image->name);
             $model->preview = $image->name;
         }
         $model->date_create = self::getCurrentDateTime();
         $model->date_update = self::getCurrentDateTime();
         if ($model->validate() && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-danger'], 'body' => Yii::t('app', 'Error. Incorrect data')]);
             return $this->redirect(['index']);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:Wulfagor,项目名称:Testing-Task,代码行数:31,代码来源:BooksController.php

示例2: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     $session = Yii::$app->session;
     if (strripos($_SERVER['HTTP_REFERER'], 'BooksSearch') || strripos($_SERVER['HTTP_REFERER'], 'sort')) {
         $session->set('redirect_param', $_SERVER['HTTP_REFERER']);
     }
     if ($model->load(Yii::$app->request->post())) {
         $file_image = UploadedFile::getInstance($model, 'image');
         if ($file_image && $file_image->tempName) {
             $model->image = $file_image;
             if ($model->validate(['image'])) {
                 $base_patch = 'uploads/';
                 $dir = Yii::getAlias('../web/' . $base_patch);
                 $fileName = $model->image->baseName . '.' . $model->image->extension;
                 $model->image->saveAs($dir . $fileName);
                 $model->image = $fileName;
                 $model->image = $dir . $fileName;
                 $model->preview = $base_patch . $fileName;
             }
         }
         if ($model->save()) {
             return isset($session['redirect_param']) ? $this->redirect($session->get('redirect_param')) : $this->redirect(['index']);
             //return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:Diakonrus,项目名称:test_zadanie,代码行数:34,代码来源:BooksController.php

示例3: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post())) {
         if (!$model->validate()) {
             yii::$app->session->setFlash('create_bad', yii::t('app', 'New book not has been created'));
             return $this->redirect(['index']);
         }
         // upload new preview
         $model->upload_preview = UploadedFile::getInstance($model, 'upload_preview');
         if ($model->upload_preview) {
             if (($model->upload_preview->type == 'image/jpeg' or $model->upload_preview->type == 'image/png' or $model->upload_preview->type == 'image/gif' or $model->upload_preview->type == 'image/svg+xml') and $model->upload_preview->size < 999999) {
                 $preview_name_arr = preg_replace("~[ :-]~", "_", explode(".", $model->upload_preview->name));
                 $preview_name = $preview_name_arr[0] . '__' . time() . "." . $model->upload_preview->extension;
                 $model->upload_preview->saveAs('img/small/' . $preview_name, false);
                 $model->upload_preview->saveAs('img/original/' . $preview_name);
                 $model->preview = $preview_name;
             } else {
                 yii::$app->session->setFlash('upload_preview_bad', yii::t('app', 'Preview not uploaded: error type or big size'));
             }
         }
         // возвращаю к формату согласно БД
         $model->date_create = time();
         $model->date_update = time();
         $model->date = Yii::$app->formatter->asTimestamp($model->date);
         $model->save();
         yii::$app->session->setFlash('create_ok', yii::t('app', 'New book - <i>{name}</i> - has been successfully created', array('name' => $model->name)));
         return $this->redirect(Url::previous());
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }
开发者ID:krausweb,项目名称:yiibooks,代码行数:37,代码来源:BooksController.php

示例4: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:Araused,项目名称:books,代码行数:13,代码来源:BooksController.php

示例5: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }
开发者ID:ZlatanNikolich,项目名称:yiisrk,代码行数:14,代码来源:BooksController.php

示例6: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'authors' => $this->getAuthorsArray(Authors::find()->all())]);
     }
 }
开发者ID:alaz1987,项目名称:books,代码行数:14,代码来源:BooksController.php

示例7: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post())) {
         $model->uploadImage();
         return $model->save() ? $this->redirect(['index']) : var_dump($model);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:akomyagin,项目名称:books,代码行数:15,代码来源:BooksController.php

示例8: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     $model->date_create = $model->date_update = date('Y-m-d H:i:s');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(isset($_POST['referer']) ? $_POST['referer'] : '/');
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:Pontorez,项目名称:kgr,代码行数:15,代码来源:BooksController.php

示例9: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $book = new Books();
     $author = new Authors();
     if ($book->load(Yii::$app->request->post()) && $book->save()) {
         return $this->redirect(['view', 'id' => $book->id]);
     } else {
         return $this->render('create', ['model' => $book, 'author' => $author]);
     }
 }
开发者ID:sergioIt,项目名称:basicdev,代码行数:15,代码来源:BooksController.php

示例10: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($closeOnLoad = false)
 {
     $model = new Books();
     $data = $this->filterData(Yii::$app->request->post());
     if ($model->load($data) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id, 'closeOnLoad' => $closeOnLoad]);
     } else {
         return $this->render('create', ['model' => $model, 'authors' => $this->getAuthorsForDropDownList()]);
     }
 }
开发者ID:alhimik1986,项目名称:test_for_job,代码行数:15,代码来源:BooksController.php

示例11: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     $model->scenario = 'create';
     if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
         if ($this->loadPreview($model) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:IuriiP,项目名称:test160107,代码行数:16,代码来源:BooksController.php

示例12: actionCreate

 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post())) {
         $model->uploadImage();
         $model->date_create = date('Y-m-d');
         $model->date_update = date('Y-m-d');
         $model->save();
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:verve000,项目名称:verve000,代码行数:13,代码来源:BooksController.php

示例13: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     if ($model->load(Yii::$app->request->post()) && $model->upload()) {
         //var_dump(Yii::$app->request->post());die();
         if ($model->save()) {
             return $this->redirect(['index']);
         } else {
             return $this->render('create', ['authors' => Authors::find()->all(), 'model' => $model]);
         }
     } else {
         return $this->render('create', ['authors' => Authors::find()->all(), 'model' => $model]);
     }
 }
开发者ID:logs12,项目名称:books,代码行数:19,代码来源:BooksController.php

示例14: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     $model_b_a_rel = new BookAuthorRel();
     $authorsArr = Authors::authorArr();
     if ($model->load(Yii::$app->request->post()) && $model_b_a_rel->load(Yii::$app->request->post())) {
         $model->save();
         $model_b_a_rel->b_id = $model->id;
         $model_b_a_rel->saveMultiple();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'model_b_a_rel' => $model_b_a_rel, 'authorsArr' => $authorsArr]);
     }
 }
开发者ID:snedi,项目名称:book-management,代码行数:19,代码来源:BooksController.php

示例15: actionCreate

 /**
  * Creates a new Books model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Books();
     $modelAuthorsBooks = new AuthorsBooks();
     $data = Yii::$app->request->post();
     if ($model->load($data) && $model->save()) {
         $modelAuthorsBooks->a_id = $data['AuthorsBooks']['a_id'][0];
         $modelAuthorsBooks->b_id = $model->id;
         if ($modelAuthorsBooks->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'modelAuthorsBooks' => $modelAuthorsBooks]);
     }
 }
开发者ID:snedi,项目名称:imot,代码行数:20,代码来源:BooksController.php


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