当前位置: 首页>>代码示例>>PHP>>正文


PHP User::forceSave方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:45,代码来源:User.php


注:本文中的RainLab\User\Models\User::forceSave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。