使用角色功能获取角色

问题描述 投票:0回答:1

是否有办法获得所有角色,包括(id和rolename)

function getrole {
    $options = array();
    foreach (role_get_names() as $myrole) {
       $options[$myrole->id] = $myrole->localname;
    }
    return html_writer::select($options);       
}
moodle
1个回答
0
投票
// The true at the end is used to return an array for select elements.
// So this returns an array with array(roleid => 'originalrolename')
$options = role_fix_names(get_all_roles(), context_system::instance(), ROLENAME_ORIGINAL, true);
© www.soinside.com 2019 - 2024. All rights reserved.