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


PHP Books::validate方法代码示例

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


在下文中一共展示了Books::validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
 {
     $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

示例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();
     if ($model->load(Yii::$app->request->post())) {
         $upload_file = $model->uploadFile();
         var_dump($model->validate());
         if ($model->validate()) {
             if ($model->save()) {
                 if ($upload_file !== false) {
                     $path = $model->getUploadedFile();
                     $upload_file->saveAs($path);
                 }
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:fedman,项目名称:books,代码行数:23,代码来源: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()) && $model->validate()) {
         if ($this->saveUpload($model)) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:gluck1986,项目名称:yii2test,代码行数:15,代码来源: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->validate()) {
         $file = UploadedFile::getInstance($model, 'image');
         $model->image = $file;
         // Если изображение выбрано, загрузить его
         if (!empty($model->image)) {
             $filename = uniqid();
             $model->image = $file;
             $model->preview = $filename . "." . $model->image->getExtension();
             if ($model->save()) {
                 $file->saveAs($model->getUplDir() . $filename . "." . $model->image->getExtension());
                 return $this->redirect(["index"]);
             }
         } else {
             if ($model->save()) {
                 return $this->redirect(["index"]);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:74Genesis,项目名称:BooksCatalog-yii2,代码行数:28,代码来源:BooksController.php


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