如何使用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);
最佳答案
我认为问题在于您将 $register
(最后一个参数)指定为 TRUE
。仅在创建新帐户时使用,因此如果设置,您将只能保存注册页面上可用的个人资料字段,这可能不是您想要的。
由于它不是必需参数,因此您可以将其省略。
当涉及到编辑格式时,如果值来自表单,则它期望与您所拥有的 $form_state['values']
格式相同,例如:
<?php
$edit = array(
'fencing_style' => 'Aggressive',
'favorite_weapon' => 'sabre',
'left_handed' => FALSE,
);
profile_save_profile($edit, $user, 'Fencing Information');
关于php - 德鲁帕尔 6 : Programmatically Altering User Values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1291140/