欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal6 drupal7 d6 d7 根据 用户名 名称 得到 返回 用户 uid user_load 根据 name 得到 user 根据名字得到用户 根据姓名得到用户 根据 email mail 邮箱 有大用 有大大用

1) 第一种方法

 drupal6
user.module user_load($user_info = array()) $account = user_load(array('name' => check_plain($name))); https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load/6.x
  

drupal7 可以通过 user_load_by_name user_load_by_mail 等方法 研究下 user_load_multiple ,调用 user_load_multiple 方法

user_load_multiple

function user_load_by_name($name) {
$users = user_load_multiple(array(), array('name' => $name));
return reset($users);
}
function user_load_by_mail($mail) {
$users = user_load_multiple(array(), array('mail' => $mail));
return reset($users);
}



1) 第种方法$account = user_load_by_name($user_name); //好像drupal 6 不行

function user_load_by_name($name) {
  $users = user_load_multiple(array(), array('name' => $name));
  return reset($users);
}



if (user_access('access administration pages', $account)) {
  // Do something
}

2) 种方法


function get_uid($username) { 
// Function that returns the uid based on the username given 
   $user = db_fetch_object(db_query("SELECT uid FROM users WHERE name=':username'", array(":username" => $username))); return $user->uid; 
}



4) 第四种方法

// Add the user you want to find here $user_to_lookup = 'test'; 
$users = entity_load('user'); 
$found_user = null; 
foreach ($users as $user) 
{ 
    if ($user->name == $user_to_lookup ) { 
     $found_user = $user; 
    } 
}



 





$account = user_load(array('name' => check_plain($name)));


普通分类: