本文整理汇总了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]);
}
示例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);
}
}
示例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]);
}
}
示例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';
}
}