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


PHP Customer::validate方法代碼示例

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


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

示例1: actionCreateMultipleModels

 public function actionCreateMultipleModels()
 {
     $models = [];
     $OK = true;
     if (isset($_POST['Customer'])) {
         foreach ($_POST['Customer'] as $postObj) {
             $customer = new Customer();
             $customer->attributes = $postObj;
             $isValid = $customer->validate();
             $OK = $OK && $isValid;
             $models[] = $customer;
         }
         if ($OK) {
             foreach ($models as $model) {
                 $model->save();
             }
             $this->redirect('customers/grid');
         }
     } else {
         for ($i = 0; $i < 3; $i++) {
             $models[] = new Customer();
         }
     }
     return $this->render('createMultipleModels', compact('models'));
 }
開發者ID:soanni,項目名稱:yii2news,代碼行數:25,代碼來源:CustomersController.php

示例2: actionCreateMultipleModels

 public function actionCreateMultipleModels()
 {
     $models = [];
     if (isset($_POST['Customer'])) {
         $validateOK = true;
         foreach ($_POST['Customer'] as $postObj) {
             $model = new Customer();
             $model->attributes = $postObj;
             $models[] = $model;
             $validateOK = $validateOK && $model->validate();
         }
         // All models are validated and will be saved
         if ($validateOK) {
             foreach ($models as $model) {
                 $model->save();
             }
             // Redirect to grid after save
             return $this->redirect(['grid']);
         }
     } else {
         for ($k = 0; $k < 3; $k++) {
             $models[] = new Customer();
         }
     }
     return $this->render('createMultipleModels', ['models' => $models]);
 }
開發者ID:QiLiuXianSheng,項目名稱:yii2,代碼行數:26,代碼來源:CustomersController.php

示例3: actionCreateCustomerAndReservation

 public function actionCreateCustomerAndReservation()
 {
     $customer = new Customer();
     $reservation = new Reservation();
     $reservation->customer_id = 0;
     if ($customer->load(Yii::$app->request->post()) && $reservation->load(Yii::$app->request->post()) && $customer->validate() && $reservation->validate()) {
         $dbTrans = Yii::$app->db->beginTransaction();
         $customerSaved = $customer->save();
         if ($customerSaved) {
             $reservation->customer_id = $customer->id;
             $reservationSaved = $reservation->save();
             if ($reservationSaved) {
                 $dbTrans->commit();
             } else {
                 $dbTrans->rollback();
             }
         } else {
             $dbTrans->rollback();
         }
     }
     return $this->render('createCustomerAndReservation', ['customer' => $customer, 'reservation' => $reservation]);
 }
開發者ID:AntoninSlejska,項目名稱:yii-test,代碼行數:22,代碼來源:ReservationsController.php

示例4: actionCreateCustomerAndReservation

 public function actionCreateCustomerAndReservation()
 {
     $customer = new \app\models\Customer();
     $reservation = new \app\models\Reservation();
     // It is useful to set fake customer_id to reservation model to avoid validationerror (because customer_id is mandatory)
     $reservation->customer_id = 0;
     if ($customer->load(Yii::$app->request->post()) && $reservation->load(Yii::$app->request->post()) && $customer->validate() && $reservation->validate()) {
         $dbTrans = Yii::$app->db->beginTransaction();
         $customerSaved = $customer->save();
         if ($customerSaved) {
             $reservation->customer_id = $customer->id;
             $reservationSaved = $reservation->save();
             if ($reservationSaved) {
                 $dbTrans->commit();
             } else {
                 $dbTrans->rollback();
             }
         } else {
             $dbTrans->rollback();
         }
     }
     return $this->render('createCustomerAndReservation', ['customer' => $customer, 'reservation' => $reservation]);
 }
開發者ID:QiLiuXianSheng,項目名稱:yii2,代碼行數:23,代碼來源:ReservationsController.php


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