Drupal:获取用户信息

时间:2010-07-09 08:03:43

标签: drupal drupal-6 profile

如何在加载随机网站页面时获取有关登录用户的信息?

我需要抓取个人资料字段来自定义页面外观

感谢

4 个答案:

答案 0 :(得分:1)

以下是您可以使用的一系列变量的列表:http://web.rhizom.nl/development/drupal-variables-in-theme-files/

此页面显示如何获取用户电子邮件地址等变量:http://11heavens.com/Drupal-coder-lost-in-space/who-is-she

答案 1 :(得分:1)

Erics的回答适用于主题。模块中的标准方法是执行global $user以获取登录用户。我个人不喜欢以这种方式使用全局变量但是在罗马时...

答案 2 :(得分:1)

当前用户信息始终以全局形式提供,因此您只需执行以下操作:

global $user;
// $user will now be a stdClass object representing the current user, logged in or not
// If you are only interested in logged in users, a standard check would be
if (0 != $user->uid) {
  // Do something for/with logged in users
}

匿名用户将拥有uid 0,admin(第一个)用户将拥有1。

答案 3 :(得分:0)

始终在使用函数user_load()获取的任何用户对象中加载配置文件值。全局变量$user包含当前登录用户的信息。如果要查找名为profile_realname的配置文件的值,可以使用以下代码:

global $user:

// Avoid the anonymous user, which doesn't have any profile field.
if ($user->uid) {
  $realname = $user->profile_realname;
}
相关问题