Moodle 'core_course_get_contents' 不工作
Moodle 'core_course_get_contents' not working
我正在 Moodle 3.3 中实现一个简单的网络服务客户端并测试一些功能。出于某种原因,这似乎不起作用。
<?php
$token = '.......';
$domainname = 'http://localhost/moodle';
$functionname = 'core_course_get_contents';
$cid = 5;
/// SOAP CALL
$serverurl = $domainname . '/webservice/soap/server.php'. '?wsdl=1&wstoken=' . $token;
////Do the main soap call
$client = new SoapClient($serverurl);
try {
$resp = $client->__soapCall($functionname, array($cid));
} catch (Exception $e) {
print_r($e);
}
if (isset($resp)) {
print_r($resp);
}
我不断收到以下错误:
SoapFault Object ( [message:protected] => Invalid parameter value detected | ERRORCODE: invalidparameter [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/html/client.php [line:protected] => 15 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/html/client.php [line] => 15 [function] => __soapCall [class] => SoapClient [type] => -> [args] => Array ( [0] => core_course_get_contents [1] => Array ( [0] => 5 ) ) ) ) [previous:Exception:private] => [faultstring] => Invalid parameter value detected | ERRORCODE: invalidparameter [faultcode] => Receiver [faultactor] => invalidparameter [detail] => options => Invalid parameter value detected: Only arrays accepted. The bad value is: '' )
网络服务的文档是:
REST (POST parameters)
courseid= int
XML-RPC (PHP structure)
[options] =>
Array
(
[0] =>
Array
(
[name] => string
[value] => string
)
)
预期的参数是:
- 课程编号
- 选项(可选)
因此,我希望调用类似于:
$resp = $client->__soapCall($functionname, array('courseid' => $cid));
如果您想指定任何选项,它看起来像:
$resp = $client->__soapCall($functionname, array('courseid' => $cid, 'options' => [['name' => 'nameofoption', 'value' => 'valuetoset'], ['name' => 'secondoption', 'value' => 'secondvalue]]));
我正在 Moodle 3.3 中实现一个简单的网络服务客户端并测试一些功能。出于某种原因,这似乎不起作用。
<?php
$token = '.......';
$domainname = 'http://localhost/moodle';
$functionname = 'core_course_get_contents';
$cid = 5;
/// SOAP CALL
$serverurl = $domainname . '/webservice/soap/server.php'. '?wsdl=1&wstoken=' . $token;
////Do the main soap call
$client = new SoapClient($serverurl);
try {
$resp = $client->__soapCall($functionname, array($cid));
} catch (Exception $e) {
print_r($e);
}
if (isset($resp)) {
print_r($resp);
}
我不断收到以下错误:
SoapFault Object ( [message:protected] => Invalid parameter value detected | ERRORCODE: invalidparameter [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/html/client.php [line:protected] => 15 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/html/client.php [line] => 15 [function] => __soapCall [class] => SoapClient [type] => -> [args] => Array ( [0] => core_course_get_contents [1] => Array ( [0] => 5 ) ) ) ) [previous:Exception:private] => [faultstring] => Invalid parameter value detected | ERRORCODE: invalidparameter [faultcode] => Receiver [faultactor] => invalidparameter [detail] => options => Invalid parameter value detected: Only arrays accepted. The bad value is: '' )
网络服务的文档是:
REST (POST parameters)
courseid= int
XML-RPC (PHP structure)
[options] =>
Array
(
[0] =>
Array
(
[name] => string
[value] => string
)
)
预期的参数是:
- 课程编号
- 选项(可选)
因此,我希望调用类似于:
$resp = $client->__soapCall($functionname, array('courseid' => $cid));
如果您想指定任何选项,它看起来像:
$resp = $client->__soapCall($functionname, array('courseid' => $cid, 'options' => [['name' => 'nameofoption', 'value' => 'valuetoset'], ['name' => 'secondoption', 'value' => 'secondvalue]]));