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


PHP Product::validate方法代码示例

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


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

示例1: actionCreate

 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(\Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('form', ['model' => $model]);
 }
开发者ID:afernandes465,项目名称:fafediesel,代码行数:10,代码来源:ProductController.php

示例2: actionCreate

 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $model_category = new Category();
     $model_product_category = new ProductCategory();
     $model_manufacturer = new Manufacturer();
     $model_product_manufacturer = new ProductManufacturer();
     $upload_model = new UploadForm();
     $resource = new Resources();
     $resource_product = new ResourcesProduct();
     if (isset($_POST['Product']) && !empty($_POST['Product'])) {
         $model->attributes = $_POST['Product'];
         $model->beforeSave(TRUE);
         if ($model->validate() && $model->save()) {
             if (empty($_POST['ProductCategory']['category_id'])) {
                 $model_product_category->addError('category_id', 'No category selected.');
             } else {
                 foreach ($_POST['ProductCategory']['category_id'] as $category) {
                     $model_product_category = new ProductCategory();
                     $model_product_category->product_id = $model->id;
                     $model_product_category->category_id = $category;
                     $model_product_category->save();
                 }
             }
             if (isset($_POST['ProductManufacturer']) && !empty($_POST['ProductManufacturer']['manufacturer_id'])) {
                 $model_product_manufacturer->attributes = $_POST['ProductManufacturer'];
                 $model_product_manufacturer->product_id = $model->id;
                 $model_product_manufacturer->save();
             }
             $upload_model->imageFiles = UploadedFile::getInstances($upload_model, 'imageFiles');
             $uploaded_files = $upload_model->upload('product_image');
             if (!empty($uploaded_files)) {
                 foreach ($uploaded_files as $uploaded_file) {
                     $resource = new Resources();
                     $resource->attributes = $uploaded_file;
                     $resource->beforeSave(TRUE);
                     if ($resource->validate() && $resource->save()) {
                         $resource_product = new ResourcesProduct();
                         $resource_product->product_id = $model->id;
                         $resource_product->resources_id = $resource->id;
                         $resource_product->save();
                     }
                 }
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'model_manufacturer' => $model_manufacturer, 'model_product_manufacturer' => $model_product_manufacturer, 'model_category' => $model_category, 'model_product_category' => $model_product_category, 'upload_model' => $upload_model]);
     }
 }
开发者ID:md-nurul-islam,项目名称:simple-ecom,代码行数:55,代码来源:ProductController.php

示例3: _getProductData

 private function _getProductData($url)
 {
     $url = trim($url);
     if (strlen($url) > 0 && !$this->is_404($url)) {
         $product_model = new Product();
         $product_info = ['category_id' => '', 'name' => '', 'description' => '', 'size' => '', 'price' => 0.0, 'details' => '', 'original_url' => '', 'created_ts' => time()];
         $category = Yii::$app->request->post('category');
         if (!empty($category)) {
             $product_info['category_id'] = $category;
         }
         $imgdir = Yii::getAlias('@uploadPath') . '/products/';
         $html = file_get_html($url);
         $product_info['original_url'] = $url;
         $product_name = $html->find('h1.top_title', 0);
         // Get Product name
         if (isset($product_name->innertext) && !empty($product_name->innertext)) {
             //Only save product if it has name
             $product_info['name'] = $product_name->innertext;
             $img = $html->find('img.lg_view', 0);
             //Get Product image
             $src = 'http:' . $img->src;
             $file_name = urldecode(end(explode('/', $img->src)));
             if (isset($img->src) && @copy($src, $imgdir . $file_name)) {
                 $product_info['image'] = $file_name;
             }
             $price = $html->find('span.priceshow', 0);
             //Get Product size
             if (isset($price->innertext)) {
                 $product_price = end(explode('$', $price->innertext));
                 $product_info['price'] = $product_price;
             }
             $description = $html->find('div.explain p', 1);
             //Get Product description
             if (isset($description->innertext)) {
                 $product_info['description'] = trim($description->innertext);
             }
             $product_model->attributes = $product_info;
             if ($product_model->validate()) {
                 if ($product_model->save()) {
                     //return $this->redirect(['products/view/' . $product_model->id]);
                     //return $this->refresh();
                 } else {
                     Yii::$app->session->setFlash('saveErr', 'An error occurred. Please try again!');
                 }
             } else {
                 Yii::$app->session->setFlash('saveErr', 'An error occurred. Please try again!');
             }
         }
     }
 }
开发者ID:veerkun,项目名称:sunfrog,代码行数:50,代码来源:ProductsController.php


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