本文整理汇总了PHP中Booking::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Booking::setAttribute方法的具体用法?PHP Booking::setAttribute怎么用?PHP Booking::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Booking
的用法示例。
在下文中一共展示了Booking::setAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate($shipment_id = '')
{
$model = new Booking();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
$awb = '';
if (is_numeric($shipment_id)) {
$shipment = Shipment::model()->findByPk($shipment_id);
if ($shipment instanceof Shipment) {
$model->address = $shipment->shipper_address;
$model->city = $shipment->shipper_city;
$model->postal = $shipment->shipper_postal;
$model->country = $shipment->shipper_country;
$model->phone = $shipment->shipper_phone;
$model->shipment_id = $shipment->id;
$awb = $shipment->awb;
}
}
if (isset($_POST['Booking'])) {
$model->attributes = $_POST['Booking'];
$model->setAttribute('booking_code', dechex(time()));
if ($model->save()) {
if (!empty($model->shipment_id) || $model->shipment_id != '') {
$shipment->booking_id = $model->id;
$tes = $shipment->update();
}
Yii::app()->user->setFlash('success', 'Success to add new booking, ' . $model->booking_code);
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model, 'awb' => $awb));
}
示例2: actionRequestPickUp
public function actionRequestPickUp()
{
$req = Yii::app()->request;
$shipment_id = $req->getQuery('shipment_id');
if (!isset($_POST['Booking'])) {
echo CJSON::encode($this->statusError('Must be in POST method'));
Yii::app()->end();
}
$booking = new Booking();
$booking->setAttributes($_POST['Booking']);
$booking->setAttribute('booking_code', dechex(time()));
if ($shipment_id != null) {
$shipment = Shipment::model()->findByPk($shipment_id);
if (!$shipment instanceof Shipment) {
echo CJSON::encode($this->statusError('Your Shipment is invalid'));
Yii::app()->end();
}
}
$trans = Yii::app()->db->beginTransaction();
try {
if ($booking->save()) {
if (isset($shipment) && $shipment instanceof Shipment) {
Booking::model()->updateByPk($booking->id, array('customer_id' => $shipment->customer_id));
$shipment->setAttribute('booking_id', $booking->id);
if (!$shipment->save()) {
throw ServiceControllerException($shipment->getErrors());
}
} else {
if ($this->token instanceof Token) {
$customer = Customer::model()->findByPk($this->token->customer_id);
if (!$customer instanceof Customer) {
throw new ServiceControllerException('You have to login first');
} else {
Booking::model()->updateByPk($booking->id, array('customer_id' => $customer->id));
}
} else {
$customer = new Customer();
$customer->name = $booking->name;
$customer->type = 'personal';
$customer->accountnr = 'WEB' . time();
if ($customer->save()) {
$contact = new Contact();
$contact->parent_id = $customer->id;
$contact->parent_model = 'Customer';
$contact->full_name = $booking->name;
$contact->address = $booking->address;
$contact->country = $booking->country;
$contact->city = $booking->city;
$contact->postal = $booking->postal;
if ($contact->save()) {
Booking::model()->updateByPk($booking->id, array('customer_id' => $customer->id));
} else {
throw new ServiceControllerException($contact->getErrors());
}
} else {
throw new ServiceControllerException($customer->getErrors());
}
}
}
$data = array('booking_code' => $booking->booking_code);
} else {
throw ServiceControllerException($booking->getErrors());
}
$trans->commit();
} catch (ServiceControllerException $e) {
$errors = $e->errors;
$trans->rollback();
echo CJSON::encode($this->statusError($errors));
Yii::app()->end();
}
echo CJSON::encode($this->statusSuccess($data));
Yii::app()->end();
}