2

您如何使用 profile_save_profile?

foreach ($users as $user) { //list of users to act on
    $by_user = views_get_view_result('attendance', 'page_3', array($user->uid)); //view containing info about this user
    $edit = array('profile_attendance_short_term' => substr(count($by_user) / count($general), 0, 5)); //calculation

    profile_save_profile($edit, $user->uid, 'Fencing Information', TRUE); //update user profile???
}

我究竟做错了什么?

编辑:这也失败了:

$edit = array('profile_attendance_short_term' => 9001);

profile_save_profile($edit, user_load(3), 'Fencing Information', TRUE);
4

2 回答 2

3

我认为问题在于您将$register(最后一个参数)指定为TRUE. 这仅在创建新帐户时使用,因此如果设置,您将只能保存注册页面上可用的配置文件字段,这可能不是您想要的。

由于它不是必需的参数,因此您可以将其省略。

当涉及到编辑格式时,它期望与$form_state['values']来自表单的值相同的格式,例如:

<?php
$edit = array(
  'fencing_style' => 'Aggressive',
  'favorite_weapon' => 'sabre',
  'left_handed' => FALSE,
);
profile_save_profile($edit, $user, 'Fencing Information');
于 2009-08-18T18:13:04.663 回答
0

查看 profile_save_profile 函数,它似乎希望传入 $user 而不是 $user->uid - 所以尝试修改您的调用如下:

profile_save_profile($edit, $user, 'Fencing Info', TRUE); 
于 2009-08-18T16:40:19.280 回答