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

这里的技术是共享的

You are here

根据角色名得到角色id rolename roleid rid 有大用

shiping1 的头像

This is quite straightforward with user_roles() and array_search(). Below is a function which will return the role ID if there is a role matching the name and FALSE otherwise.

function get_role_by_name($name) {
  $roles = user_roles();
  return array_search($name, $roles);
}

// 例子  根据角色名得到角色id
$rid = get_role_by_name('administrator');

One liner would be:

$rid = array_search('administrator', user_roles);

来自 http://drupal.stackexchange.com/questions/50435/how-do-i-find-the-role-id-from-role-name
普通分类: