當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::save方法代碼示例

本文整理匯總了PHP中app\models\Product::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::save方法的具體用法?PHP Product::save怎麽用?PHP Product::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Product的用法示例。


在下文中一共展示了Product::save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: store

 public function store(EditProductRequest $request)
 {
     $product = new Product();
     $product->fill($request->only($product->getFillable()));
     $product->save();
     return redirect()->route('product.index')->with('success_message', 'The product has been successfully saved.');
 }
開發者ID:rundef,項目名稱:laravel_backbone,代碼行數:7,代碼來源: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();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (isset($_POST['name']) && is_array($_POST['name'])) {
             foreach ($_POST['name'] as $lang => $val) {
                 $model->setName($lang, $val);
             }
         }
         if (isset($_POST['description']) && is_array($_POST['description'])) {
             foreach ($_POST['description'] as $lang => $val) {
                 $model->setDescription($lang, $val);
             }
         }
         if (isset($_POST['information']) && is_array($_POST['information'])) {
             foreach ($_POST['information'] as $lang => $val) {
                 $model->setInformation($lang, $val);
             }
         }
         $model->updateURLCode();
         return $this->redirect(['update', 'id' => $model->id, 'panel' => 'images']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:rcjusto,項目名稱:simplestore,代碼行數:30,代碼來源:ProductController.php

示例3: createItem

 /**
  *
  * @param $item
  */
 public function createItem($item)
 {
     $product = new Product();
     $product->name = $item['name'];
     $product->description = $item['description'];
     $product->price = $item['price'];
     $product->sell_price = $item['sell_price'];
     $product->created = date('Y-m-d H:i:s');
     $product->updated = date('Y-m-d H:i:s');
     $product->save();
     //update image after save product
     if (isset($item['image']) && $item['image'] !== 'undefined') {
         $this->updateImage($item['image'], $product->id);
     }
     //update description with image
     if (!empty($item['description'])) {
         $this->updateDescWithImg($item['description'], $product->id);
     }
     //add tags
     if (!empty($item['tags'])) {
         foreach ($item['tags'] as $k => $v) {
             $product->tag()->attach($v);
         }
     }
 }
開發者ID:kacana,項目名稱:admin,代碼行數:29,代碼來源:Product.php

示例4: uploadMenuJson

 public function uploadMenuJson($restaurant_id)
 {
     $col0 = "col_0";
     $col1 = "col_1";
     $col2 = "col_2";
     $warehouse = null;
     $product = null;
     Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/web/upload/';
     $this->jsonFile = UploadedFile::getInstance($this, 'jsonFile');
     $this->jsonFile->saveAs(Yii::$app->params['uploadPath'] . $this->jsonFile->baseName . '.' . $this->jsonFile->extension);
     $json = json_decode(file_get_contents(Yii::$app->params['uploadPath'] . $this->jsonFile), true);
     $product_id = Product::find()->orderBy(['product_id' => SORT_DESC])->one()->product_id;
     $product_id++;
     foreach ($json as $array) {
         $warehouse = new Warehouse();
         $product = new Product();
         $product->name = $array[$col0];
         $product->description = $array[$col1];
         $product->save();
         $warehouse->restaurant_id = $restaurant_id;
         $warehouse->product_id = $product_id;
         $warehouse->price = $array[$col2];
         $warehouse->save();
         $product_id++;
     }
     return true;
 }
開發者ID:vodas,項目名稱:praktykigda,代碼行數:27,代碼來源:FileUpload.php

示例5: postCreate

 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Product::$rules);
     if ($validator->passes()) {
         $product = new Product();
         $product->name = Input::get('name');
         $product->category_id = Input::get('category_id');
         $product->short_description = Input::get('short_description');
         $product->long_description = Input::get('long_description');
         $product->is_discount = Input::get('is_discount');
         $product->discount = Input::get('discount');
         $product->count_for_discount = Input::get('count_for_discount');
         $product->is_default_discount = Input::get('is_default_discount');
         $product->default_discount = Input::get('default_discount');
         $product->price = Input::get('price');
         $product->amount = Input::get('amount');
         $product->yellow_qty = Input::get('yellow_qty');
         $product->red_qty = Input::get('red_qty');
         $product->code_1c = Input::get('code_1c');
         $product->article = Input::get('article');
         $product->availability = Input::get('availability');
         $product->save();
         return Redirect::to("admin/products/edit/{$product->id}")->with('message', "Продукт {$product->name} создан");
     }
     return Redirect::back()->with('message', 'Ошибка сохранения')->withErrors($validator)->withInput();
 }
開發者ID:venomir,項目名稱:tc,代碼行數:26,代碼來源:ProductController.php

示例6: 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:index0h,項目名稱:innovecs-test.pro,代碼行數:15,代碼來源:ProductController.php

示例7: setUp

 public function setUp()
 {
     parent::setUp();
     $this->shared('product', function () {
         $product = new Product(["product_name" => "iPhone 6", "product_desc" => "iPhone 6", "status" => "available", "options" => [["name" => "顏色", "options" => ["深空灰", "銀色", "金色"]], ["name" => "容量", "options" => ["16GB", "64GB", "128GB"]]], "specifications" => [["attr_name" => "高度", "attr_group" => "重量和尺寸", "attr_value" => "138.1 毫米(5.44 英寸)"], ["attr_name" => "寬度", "attr_group" => "重量和尺寸", "attr_value" => "67.0 毫米 (2.64 英寸)"], ["attr_name" => "厚度", "attr_group" => "重量和尺寸", "attr_value" => "6.9 毫米 (0.27 英寸)"], ["attr_name" => "重量", "attr_group" => "重量和尺寸", "attr_value" => "129 克 (4.55 盎司)"]]]);
         $product->save();
         return $product;
     });
 }
開發者ID:kshar1989,項目名稱:dianpou,代碼行數:9,代碼來源:ProductStockTest.php

示例8: actionCreate

 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list']);
     } else {
         $model->status = Product::STATUS_ENABLED;
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:phucnv206,項目名稱:thoitrang,代碼行數:10,代碼來源:ProductController.php

示例9: actionCreateProduct

 /**
  * Pjaxified version of ProductController actionCreate
  * @return partial
  */
 public function actionCreateProduct()
 {
     $model = new Product();
     if (Yii::$app->request->isPjax) {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             $model = new Product();
         }
         return $this->renderPartial('_product_edit', ['model' => $model]);
     }
 }
開發者ID:secondsano,項目名稱:mebel,代碼行數:14,代碼來源:AdminController.php

示例10: actionCreate

 /**
  * @param $node
  * @return string|\yii\web\Response
  */
 public function actionCreate($node)
 {
     $model = new Product();
     $model->loadDefaultValues();
     $model->category_id = $node;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list', 'node' => $node]);
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:vetoni,項目名稱:toko,代碼行數:14,代碼來源:ProductController.php

示例11: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(UpdateProductRequest $request, Product $product)
 {
     $data = $request->input();
     $product->fill($data);
     $product->save();
     $this->savePhoto($product, $request);
     $product->categories()->detach($product->categories()->lists('id')->toArray());
     $product->categories()->attach($data['categories']);
     return Redirect()->route('home');
 }
開發者ID:RsanabriaZ,項目名稱:web-catalog,代碼行數:17,代碼來源:ProductController.php

示例12: create_submit

 public function create_submit()
 {
     $product = new Product();
     $product->name = \Request::get('name');
     $product->desc = \Request::get('desc');
     $product->quantity = \Request::get('quantity');
     $product->user_id = \Auth::user()->id;
     $product->status = 'SALE';
     $product->save();
     return \Redirect()->action('ProductController@index');
 }
開發者ID:comsi02,項目名稱:ordermart,代碼行數:11,代碼來源:ProductController.php

示例13: 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 = Categories::find()->all();
     // need this for dropDownList in views/product/_form.php
     $model = new Product();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'itemId' => $model->item_id]);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => $categories]);
     }
 }
開發者ID:asopin,項目名稱:shop,代碼行數:16,代碼來源:ProductController.php

示例14: fakeProduct

 protected function fakeProduct()
 {
     $fakeProduct = new Product();
     $fakeProduct->serial_number = "P1284724";
     $fakeProduct->primary_name = "Fake Product";
     $fakeProduct->product_type_id = $this->fakeProductType()->product_type_id;
     $fakeProduct->currency_id = $this->fakeCurrency()->currency_id;
     $fakeProduct->client_id = $this->fakeClient()->client_id;
     $fakeProduct->supplier_id = $this->fakeSupplier()->supplier_id;
     $fakeProduct->save();
     return $fakeProduct;
 }
開發者ID:boylee1111,項目名稱:Reservation,代碼行數:12,代碼來源:DbTestCase.php

示例15: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $product = new Product();
     $product->name = $request->input('name');
     $product->price = $request->input('price');
     $product->description = $request->input('description');
     $product->save();
     for ($i = 0; $i < $request->input('stock'); $i++) {
         $item = new ProductItem();
         $item->code = date('YmdHis') . '.' . $i;
         $item = $product->item()->save($item);
     }
 }
開發者ID:ambarsetyawan,項目名稱:laravel5-tokoonline,代碼行數:18,代碼來源:ProductController.php


注:本文中的app\models\Product::save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。