本文整理匯總了PHP中app\models\Contact::classname方法的典型用法代碼示例。如果您正苦於以下問題:PHP Contact::classname方法的具體用法?PHP Contact::classname怎麽用?PHP Contact::classname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Contact
的用法示例。
在下文中一共展示了Contact::classname方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionUpdate
/**
* Updates an existing Member model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$modelContacts = $model->contacts;
if ($model->load(Yii::$app->request->post())) {
$oldIDs = ArrayHelper::map($modelContacts, 'id', 'id');
$modelContacts = Model::createMultiple(Contact::classname(), $modelContacts);
Model::loadMultiple($modelContacts, Yii::$app->request->post());
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelContacts, 'id', 'id')));
// ajax validation
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ArrayHelper::merge(ActiveForm::ValidateMultiple($modelContacts), ActiveForm::validate($model));
}
// validate all models
$valid = $model->validate();
$valid = Model::validateMultiple($modelContacts) && $valid;
if ($valid) {
$transaction = Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
if (!empty($deletedIDs)) {
Contact::deleteAll(['id' => $deletedIDs]);
}
foreach ($modelContacts as $modelContact) {
$modelContact->member_id = $model->id;
if (!($flag = $modelContact->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
//return $this->redirect(['view', 'id' => $model->id]);
return $this->redirect($this->getReturnUrl(['view', 'id' => $model->id]));
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
}
return $this->render('update', ['model' => $model, 'modelContacts' => empty($modelContacts) ? [new Contact()] : $modelContacts]);
}