我正在尝试通过webservice在moodle中创建用户。用户是成功创建的,但自定义字段未填充。是否有人将我重定向到解决方案?在自定义字段中,我试图将性别的值作为男性发送。
$functionName = 'core_user_create_users';
$user1 = new stdClass();
$user1->username = $form_state['values']['UserName'];
$user1->password=$form_state['values']['PassWord'];
$user1->firstname = $form_state['values']['FirstName'];
$user1->lastname = $form_state['values']['LastName'];
$user1->email = $form_state['values']['Emailid'];
$user1->mailformat = '0';
$preferencename1 = 'auth_forcepasswordchange';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'true')
);
$user1->customfields = array(
array('type' => 'Gender', 'value' => 'Male')
);
$users = array($user1);
$params = array('users' => $users);
/// REST CALL
$rest_format = 'json';
//$server_url = $domain_name . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $function_name;
$server_url = 'localhost/moodle' . '/webservice/rest/server.php'. '?wstoken=' . '7525ce057d455657a4e83d7aa63f3684' .'&wsfunction='. $functionName;
require_once('curl.inc');
$curl = new curl;
$rest_format = ($rest_format == 'json') ? '&moodlewsrestformat=' . $rest_format : '';
$resp =$curl->post($server_url.$rest_format , $params);
dpm($resp);
$res=json_decode($resp);
dpm($res);
答案 0 :(得分:1)
$preferencename1 = 'auth_forcepasswordchange';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'true')
);
有效吗? 我正在尝试但显示无效的参数错误。
答案 1 :(得分:0)
我明白了。我所做的一切都是因为性别的第一封信应该是小写的。它应该是gender
而不是Gender
。