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


PHP Order::validate方法代码示例

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


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

示例1: actionOrder

 public function actionOrder()
 {
     $order = new Order();
     $products = $this->_cart->getPositions();
     $total = $this->_cart->getCost();
     if ($order->load(\Yii::$app->request->post()) && $order->validate()) {
         $order->user_id = 1;
         $order->cart_id = "text";
         if ($order->save(false)) {
             foreach ($products as $product) {
                 $orderItem = new OrderItem();
                 $orderItem->order_id = $order->id;
                 $orderItem->product_id = $product->id;
                 $orderItem->price = $product->getPrice();
                 $orderItem->quantity = $product->getQuantity();
                 if (!$orderItem->save(false)) {
                     \Yii::$app->session->addFlash('error', 'Cannot place your order. Please contact us.');
                     return $this->redirect('site/index');
                 }
             }
         }
         $this->_cart->removeAll();
         \Yii::$app->session->addFlash('success', 'Thanks for your order. We\'ll contact you soon.');
         //$order->sendEmail();
         return $this->redirect('site/index');
     }
     return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $total]);
 }
开发者ID:absol3112,项目名称:sonneboutique,代码行数:28,代码来源:CartController.php

示例2: createAjax

 private function createAjax()
 {
     $data = Yii::$app->request->post();
     $model = new Order(['scenario' => Order::SCENARIO_CREATE]);
     foreach ($data['Order'] as $key => $value) {
         $model->{$key} = $value;
     }
     if ($model->validate()) {
         return $model->save() ? true : ErrorHelper::errorsToString($model->errors);
     } else {
         return ErrorHelper::errorsToString($model->errors);
     }
 }
开发者ID:vodas,项目名称:praktykirepofinito,代码行数:13,代码来源:OrderController.php

示例3: actionOrder

 public function actionOrder($id)
 {
     $this->layout = 'page';
     $model = new Order();
     $categories = Category::findAll(['status' => Category::STATUS_ENABLED]);
     $product = Product::find()->where(['id' => $id, 'status' => Product::STATUS_ENABLED])->limit(1)->one();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $order = new Order();
         $order->key = strtoupper(Yii::$app->security->generateRandomString(6));
         $order->name = $product->name;
         $order->thumbnail = $product->thumbnail;
         $order->price = $product->price;
         $order->count = $model->count;
         $order->email = $model->email;
         $order->message = $model->message;
         $order->date = time();
         $order->insert();
         Yii::$app->session->set('orderID', $order->id);
         return $this->redirect(['product/confirm']);
     } else {
         return $this->render('order', ['model' => $model, 'categories' => $categories, 'product' => $product]);
     }
 }
开发者ID:phucnv206,项目名称:thoitrang,代码行数:23,代码来源:ProductController.php

示例4: actionAddorder

 /**
  *将完成的订单信息存入数据库
  */
 public function actionAddorder()
 {
     //        生成b_time count price(需要查询)
     //
     //        $timeoffset = 8;
     //        echo date('y-m-d h:i:s',time());
     //        $order->o_id = //怎么自动生成一个id
     //        $b_id 在AddOder 中  要验证seat的状态
     $order = new Order();
     $res = Yii::$app->request;
     $order->o_id = $this->actionGetoid();
     //$order->s_id = '1@qq.com';
     $order->s_id = Yii::$app->user->id;
     $order->seat_id = $res->post('seat_id');
     $order->b_time = date('y-m-d h:i:s', time());
     $order->count = count($_SESSION["dishlist"]);
     $order->desc = $res->post('desc');
     $order->price = $this->actionAccprice();
     if ($order->validate()) {
         foreach ($_SESSION['dishlist'] as $dish) {
             $one = new Orderdish();
             $one->o_id = $order->o_id;
             $one->d_id = $dish['dish_id'];
             $one->count = $dish['num'];
             $one->price = $dish['price'];
             if ($one->validate() && $one->save()) {
             } else {
                 error('error');
             }
         }
         $order->save();
         return 'success';
     } else {
         return 'fales';
     }
 }
开发者ID:trieyouth,项目名称:basic,代码行数:39,代码来源:OrderController.php


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