无法使用Web服务为用户分配角色

时间:2016-07-26 12:04:00

标签: php moodle

我正在尝试使用webservice分配角色。我已经尝试了以下代码来分配角色。

$user_id= 35;
$context_id=1;
$role_id=5;


$assignment = array( 'roleid' => $role_id, 'userid' => $user_id, 'contextid' => $context_id );
$assignments = array( $assignment );
$params = array( 'assignments' => $assignments );
$functionname = 'core_role_assign_roles';

$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
$response = $curl->post( $serverurl . $restformat, $params );

print_r( $response );

当我运行代码时,我得到了以下的响应。请帮忙。

{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected","debuginfo":"Can not assign roleid=5 in contextid=1"}

1 个答案:

答案 0 :(得分:1)

在我将角色添加到“允许角色分配”后,它才有用。编辑角色页面中的选项。

相关问题