本文整理匯總了PHP中RainLab\User\Models\User::forceSave方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::forceSave方法的具體用法?PHP User::forceSave怎麽用?PHP User::forceSave使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::forceSave方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: updateMetadata
/**
* Updates and save the metadata for a user object
*/
public function updateMetadata(OctoberUser $user, $wordpressId)
{
$metadata = $this->db->table('wp_usermeta')->where('user_id', $wordpressId)->get();
// Organize the metadata for mapping to user fields
$data = ['phone' => '', 'street_address' => '', 'city' => '', 'state' => '', 'zip' => '', 'first_name' => '', 'last_name' => '', '_badgeos_points' => '', 'email_optin' => false, 'current_member' => false, 'current_member_number' => ''];
foreach ($metadata as $mdata) {
$data[$mdata->meta_key] = $mdata->meta_value;
}
$user->phone = $data['phone'];
$user->street_addr = $data['street_address'];
$user->city = $data['city'];
$user->zip = $data['zip'];
$user->points = $data['_badgeos_points'];
// Ensures that we have a barcode id for the user
if (empty($user->barcode_id)) {
$user->barcode_id = $user->name;
}
// Populate state and country objects
if (!empty($data['state'])) {
$state = State::where('code', strtoupper($data['state']))->first();
if (!$state) {
$state = State::where('name', $data['state'])->first();
}
if ($state) {
$user->state()->associate($state);
$user->country()->associate(Country::find($state->country_id));
}
}
$metadata = new Usermeta();
$metadata->first_name = $data['first_name'];
$metadata->last_name = $data['last_name'];
$metadata->email_optin = $data['email_optin'];
$metadata->current_member = $data['current_member'];
$metadata->current_member_number = $data['current_member_number'];
try {
$user->forceSave();
$user->metadata()->delete();
$user->metadata()->save($metadata);
} catch (Exception $e) {
var_dump($e);
}
}