Drupal的6:以编程方式变更用户价值
题
你如何使用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');
其他提示
综观profile_save_profile功能,它看起来像它预期$用户中,而不是用户$> UID被传递 - 因此尝试修改您的通话如下:
profile_save_profile($edit, $user, 'Fencing Info', TRUE);
不隶属于 StackOverflow