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


PHP Product::save方法代码示例

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


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

示例1: 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();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:fnoorman,项目名称:dev,代码行数:14,代码来源:ProductController.php

示例2: actionCreate

 /**
  * Creates a new EntpProduct model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post())) {
         $model->loadDefaultValues();
         $model->save();
         if ($model->save()) {
             $produk = new EntpProduct();
             $produk->product_id = $this->id;
             $produk->entrepreneur_user_id = Yii::$app->user->id;
             $produk->link('product', $model);
         }
         Yii::$app->session->setFlash('success', 'Create New Product Success');
         return $this->redirect(['index']);
         //return $this->redirect(['view', 'entrepreneur_id' => $model->entrepreneur_id, 'product_id' => $model->product_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:azruljamil,项目名称:smev3,代码行数:24,代码来源:EntpproductController.php

示例3: 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();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', 'Товар успешно создан!');
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:ewrgergrgr,项目名称:nazar,代码行数:15,代码来源:ProductController.php

示例4: actionCreate

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

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

示例6: insert

 public function insert(ProductDto $productDto)
 {
     $product = new Product();
     if ($product->load(['Product' => ArrayHelper::toArray($productDto)])) {
         $product->type = ArrayUtil::arrayToInt($productDto->type);
         $product->save();
         return ArrayHelper::toArray($product);
     } else {
         return [];
     }
 }
开发者ID:xiaomige,项目名称:giishop,代码行数:11,代码来源:ProductServiceImpl.php

示例7: 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();
     $categoryModel = new CategoryProduct();
     $treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'treeParents' => $treeParents]);
     }
 }
开发者ID:nguyentuansieu,项目名称:OneCMS,代码行数:16,代码来源:ProductController.php

示例8: actionCreate

 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $currUser = Yii::$app->user->getIdentity();
     $currMb = MerchantBrand::find()->where(['merchant_brand_id' => $currUser->username])->one();
     $mbFk = $currMb->_id;
     $model = new Product();
     $model->merchant_brand_fk = $mbFk;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => (string) $model->_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:chimgrrl,项目名称:auction,代码行数:18,代码来源:ProductController.php

示例9: simpan

 public function simpan()
 {
     $model = new Product();
     $model->product_name = $this->name;
     $model->product_price = $this->price;
     $model->product_category = $this->category;
     $model->product_created_date = date('Y-m-d');
     $model->product_description = $this->description;
     $model->admin_id = Yii::$app->user->getId();
     $model->product_slug = $this->slug;
     $model->save();
     $this->uploadsAndSave();
 }
开发者ID:akiu,项目名称:first-yii,代码行数:13,代码来源:ProductModel.php

示例10: 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();
     if (!is_numeric($model['agreement_id'])) {
         $agreement = Agreement::find()->where(["default_flag" => 1])->asArray()->one();
         $model['agreement_id'] = $agreement['id'];
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $redirect = yii::$app->request->post('goto') == 'list' ? ['index'] : ['update', 'id' => $model->id];
         return $this->redirect($redirect);
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:kibercoder,项目名称:bilious-octo-fibula,代码行数:18,代码来源:ProductController.php

示例11: 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();
     $categoryModel = new ProductCategory();
     $companyModel = new ProductCompany();
     $treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
     $treeCompany = ArrayHelper::map($companyModel->findAll(['status' => 10]), 'id', 'title');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'treeParents' => $treeParents, 'treeCompany' => $treeCompany]);
     }
 }
开发者ID:nguyentuansieu,项目名称:BioMedia,代码行数:18,代码来源:ProductController.php

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

示例13: save

 /**
  * 保存商品
  */
 public function save()
 {
     #获得用户的地区信息用来提供浏览者的显示信息
     $userinfo = \Yii::$app->user->getIdentity();
     $newProduct = new Product();
     $newProduct->product_country = 0;
     if (!empty($userinfo->province)) {
         $newProduct->product_province = $userinfo->province;
     }
     if (!empty($userinfo->city)) {
         $newProduct->product_city = $userinfo->city;
     }
     if (!empty($userinfo->area)) {
         $newProduct->product_area = $userinfo->area;
     }
     $newProduct->setAttributes($this->attributes);
     return $newProduct->save();
 }
开发者ID:wxzuan,项目名称:wxzuan,代码行数:21,代码来源:AddProductForm.php

示例14: actionCreate

 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     // echo Yii::getAlias('@common'); exit;
     $model = new Product();
     $modelProdMeta = new ProductMeta();
     $stores = [];
     if (\Yii::$app->user->identity->id == 1) {
         $stores = \common\models\UserStore::find()->select('store_id')->where(['user_id' => Yii::$app->user->identity->id])->all();
         $stores = \yii\helpers\ArrayHelper::getColumn($stores, 'store_id');
         $storeList = \common\models\Store::find()->where(['IN', 'store_id', $stores])->all();
     } else {
         $storeList = \common\models\Store::find()->all();
     }
     if ($postData = Yii::$app->request->post()) {
         if ($model->load($postData) && $model->save()) {
             $prod_id = $model->prod_id;
             foreach ($model->cat_id as $cat) {
                 $catModel = new ProdCat();
                 $catModel->cat_id = $cat;
                 $catModel->prod_id = $prod_id;
                 $catModel->save();
             }
             $file = UploadedFile::getInstances($model, 'images');
             $model->file = $file[0];
             $image_path = Yii::getAlias('@frontend') . '/web/uploads/product/' . $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension;
             $model->file->saveAs($image_path);
             $this->updateProductMeta($id, 'prod_img', $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension);
             foreach ($postData['PMeta'] as $key => $meta_value) {
                 $this->updateProductMeta($id, $key, $meta_value);
             }
             return $this->redirect(['view', 'id' => $model->prod_id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'modelProdMeta' => $modelProdMeta, 'storeList' => $storeList]);
     }
 }
开发者ID:syedmaaz,项目名称:marxmall-,代码行数:41,代码来源:ProductController.php

示例15: actionImport

 /**
  * batch import product
  * @param integer $id
  * @return mixed
  */
 public function actionImport()
 {
     //if(!Yii::$app->user->can('viewYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $format = Product::getImportExportFormat();
     if (Yii::$app->request->post()) {
         $countCreate = $countUpdate = 0;
         $file = UploadedFile::getInstanceByName('importFile');
         $handle = fopen($file->tempName, 'r');
         $result = $this->inputCsv($handle);
         $arrData = [];
         if (count($result) <= 1) {
             Yii::$app->getSession()->setFlash('danger', Yii::t('app', 'No Record, please check file.'));
         } else {
             // 将数据的key从数字变成固定的格式
             for ($i = 1; $i < count($result); $i++) {
                 $j = 0;
                 foreach ($format as $item) {
                     $data[$item] = $result[$i][$j];
                     $j++;
                 }
                 $data['thumbs'] = $result[$i][$j];
                 $data['images'] = $result[$i][$j + 1];
                 array_push($arrData, $data);
             }
             // 处理数据,如果ID大于0,则更新,否则新增
             $line = 2;
             $errorLines = [];
             foreach ($arrData as $item) {
                 if ($item['id'] > 0) {
                     // 已存在的值,则更新数据,以及判断缩略图和图片
                     $model = Product::findOne($item['id']);
                     if ($model === null) {
                         array_push($errorLines, $line);
                         $line++;
                         continue;
                     }
                     foreach ($item as $k => $v) {
                         if ($k == 'id' || $k == 'thumbs' || $k == 'images') {
                             continue;
                         }
                         $model[$k] = iconv('gb2312', 'utf-8', trim($v));
                     }
                     $result = $model->save();
                     if (!$result) {
                         //如果保存失败
                         array_push($errorLines, $line);
                         $line++;
                         continue;
                     }
                     $countUpdate++;
                     if ($item['thumbs'] && $item['images']) {
                         $arrThumb = explode('|', $item['thumbs']);
                         $arrImage = explode('|', $item['images']);
                         $i = 0;
                         $ids = [];
                         foreach ($arrThumb as $thumb) {
                             $thumb = trim($thumb);
                             $image = trim($arrImage[$i]);
                             $productImage = ProductImage::find()->where(['product_id' => $item['id'], 'thumb' => $thumb, 'image' => $image])->one();
                             if ($productImage) {
                                 //如果图片在数据库中已经存在,则假如到ids数组,防止后续被删除
                                 array_push($ids, $productImage->id);
                             } else {
                                 //不存在的话,新增记录并将id加入到ids
                                 $productImage = new ProductImage(['product_id' => $item['id'], 'thumb' => $thumb, 'image' => $image]);
                                 $productImage->save();
                                 array_push($ids, $productImage->id);
                             }
                             $i++;
                         }
                         //删除在ids数组中记录
                         ProductImage::deleteAll(['and', 'product_id=' . $item['id'], ['not in', 'id', $ids]]);
                     }
                 } else {
                     // 新的数据,插入,并将缩略图和图片插入
                     $model = new Product();
                     foreach ($item as $k => $v) {
                         if ($k == 'id' || $k == 'thumbs' || $k == 'images') {
                             continue;
                         }
                         $model[$k] = iconv('gb2312', 'utf-8', trim($v));
                     }
                     // 将分类和品牌转换成对应的ID
                     $category = Category::find()->where(['name' => trim($model->category_id)])->one();
                     $model->category_id = $category ? $category->id : 1;
                     $brand = Brand::find()->where(['name' => trim($model->brand_id)])->one();
                     $model->brand_id = $brand ? $brand->id : 0;
                     $result = $model->save();
                     if (!$result) {
                         //如果保存失败
                         array_push($errorLines, $line);
                         $line++;
                         continue;
                     }
                     $countCreate++;
//.........这里部分代码省略.........
开发者ID:liangdabiao,项目名称:funshop,代码行数:101,代码来源:ProductController.php


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