本文整理汇总了PHP中app\models\Order::classname方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::classname方法的具体用法?PHP Order::classname怎么用?PHP Order::classname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Order
的用法示例。
在下文中一共展示了Order::classname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpdate
/**
* Updates an existing Client model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$modelClient = Client::findOne($id);
$modelsOrder = Order::findAll(['id_client' => $modelClient->id]);
if (Yii::$app->request->post() && $modelClient->load(Yii::$app->request->post())) {
$oldIDs = ArrayHelper::map($modelsOrder, 'id', 'id');
$modelsOrder = Model::createMultiple(Order::classname(), $modelsOrder);
Model::loadMultiple($modelsOrder, Yii::$app->request->post());
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsOrder, 'id', 'id')));
// validate all models
$valid = $modelClient->validate();
$valid = Model::validateMultiple($modelsOrder) && $valid;
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $modelClient->save(false)) {
if (!empty($deletedIDs)) {
Order::deleteAll(['id' => $deletedIDs]);
}
foreach ($modelsOrder as $modelOrder) {
$modelOrder->id_client = $modelClient->id;
if (!($flag = $modelOrder->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['view', 'id' => $modelClient->id]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
}
return $this->render('update', ['modelClient' => $modelClient, 'modelsOrder' => empty($modelsOrder) ? [new Order()] : $modelsOrder]);
}