0
我在moodle中编写了一个插件,它应该为某些用户分配“coursecreator”角色。如何为moodle中的用户分配“coursecreator”角色?
$coursecreatorroleid = $DB->get_field('role', 'id', array('shortname' => 'coursecreator'));
role_assign($coursecreatorroleid, $user->id,context_course::instance());
if (user_has_role_assignment($user->id, $coursecreatorroleid))
echo "True";
但它没有工作。有人可以帮我吗? 谢谢。
'context_system :: instance()'是我的答案。 Tnx很多。 –