本文整理汇总了PHP中app\models\Customer::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::getErrors方法的具体用法?PHP Customer::getErrors怎么用?PHP Customer::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Customer
的用法示例。
在下文中一共展示了Customer::getErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
try {
$admin = \Auth::User();
if (!$admin) {
return $this->failResponse('admin not logged in');
}
$customerObj = new Customer();
$data = $this->getRequestBody();
$customerObj->first_name = $data['first_name'];
$customerObj->last_name = $data['last_name'];
$customerObj->business_name = $data['business_name'];
$customerObj->mobile = $data['mobile'];
$customerObj->email = $data['email'];
$customerObj->address = $data['address'];
$customerObj->save();
if (!$customerObj->save()) {
Log::error("error in saving");
$errors = $customerObj->getErrors();
return $this->failResponse('Validation failed. Cannot save data.' . $errors);
} else {
return $this->successResponse('updated sucessfully');
}
} catch (\Exception $e) {
Log::error($customerObj->getErrors());
return $this->failResponse($e->getMessage());
}
}
示例2: 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]);
}
}
}