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


PHP Customer::tableName方法代码示例

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


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

示例1: actionCreate

 /**
  * Creates a new Bill model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Bill();
     if (Yii::$app->session['carPartTotal'] <= 0.0) {
         return;
     }
     if (isset($_POST['mode'], $_POST['discount'])) {
         $result = [];
         if ($_POST['mode'] == 0 || $_POST['mode'] == 1) {
             $transaction = $model->getDb()->beginTransaction();
             try {
                 $discount = (double) $_POST['discount'];
                 if ($discount > Yii::$app->session['carPartTotal']) {
                     $discount = 0.0;
                 }
                 $modelPrice = new Price();
                 $modelPrice->price = (double) Yii::$app->session['carPartTotal'] - (double) $discount;
                 $modelPrice->calculate();
                 if (!$modelPrice->save(false)) {
                     throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($modelPrice->tableName())), 'msj' => print_r($modelPrice->getErrors(), true)]), 500);
                 }
                 $model->price_id = $modelPrice->id;
                 $model->discount = $discount;
                 if (isset($_POST['draft']) && !empty($_POST['draft'])) {
                     $model->draft = 1;
                 }
                 if (isset($_POST['Vehicle'])) {
                     $vehicle = new Vehicle();
                     $vehicle->attributes = $_POST['Vehicle'];
                     if (!empty($vehicle->brand) || !empty($vehicle->model) || !empty($vehicle->color) || !empty($vehicle->plaque)) {
                         if (!$vehicle->save(false)) {
                             throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($vehicle->tableName())), 'msj' => print_r($vehicle->getErrors(), true)]), 500);
                         }
                         $model->vehicle_id = $vehicle->id;
                     }
                 }
                 if (isset($_POST['Customer'])) {
                     $customer = new Customer();
                     $customer->attributes = $_POST['Customer'];
                     if (!empty($customer->name) || !empty($customer->serial)) {
                         if (!$customer->save(false)) {
                             throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($customer->tableName())), 'msj' => print_r($customer->getErrors(), true)]), 500);
                         }
                         $model->customer_id = $customer->id;
                     }
                 }
                 if ($model->save()) {
                     $result['message'] = Yii::t('app', '{modelClass} saved', ['modelClass' => Yii::t('app', ucfirst($model->tableName()))]);
                 } else {
                     $result['message'] = Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => print_r($model->errors, true)]);
                 }
                 $transaction->commit();
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 $result['message'] = Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => $e]);
             }
         }
         echo json_encode($result);
     } else {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
开发者ID:edarkzero,项目名称:mi_taller,代码行数:71,代码来源:BillController.php


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