首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Drupal 6:以编程方式更改用户值

Drupal 6:以编程方式更改用户值
EN

Stack Overflow用户
提问于 2009-08-18 00:10:00
回答 2查看 3.2K关注 0票数 2

您如何使用profile_save_profile?

代码语言:javascript
复制
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???
}

我做错了什么?

编辑:这也失败了:

代码语言:javascript
复制
$edit = array('profile_attendance_short_term' => 9001);

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

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-08-18 18:13:04

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

因为它不是必需的参数,所以可以忽略它。

当谈到编辑的格式时,如果来自表单的值来自于某个表单,那么它需要与$form_state['values']相同的格式,例如:

代码语言:javascript
复制
<?php
$edit = array(
  'fencing_style' => 'Aggressive',
  'favorite_weapon' => 'sabre',
  'left_handed' => FALSE,
);
profile_save_profile($edit, $user, 'Fencing Information');
票数 3
EN

Stack Overflow用户

发布于 2009-08-18 16:40:19

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

代码语言:javascript
复制
profile_save_profile($edit, $user, 'Fencing Info', TRUE); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1291140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档