カスタム Joomla 2.5 モジュールでは、次のようにしています。
$username = $params->get('username' , '');
$password = $params->get('password' , '');
$url = $params->get('url' , 'http://api.xxxxx.com');
だから、私は構成からその変数を思い出します。
私はこの関数を書きました:
function callAPI($data) {
global $username, $password, $url;
$data['username'] = $username;
$data['password'] = $password;
$data['output'] = 'XML';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$result = curl_exec($ch);
curl_close ($ch);
$parsed_result = new SimpleXMLElement(str_replace('&','&',$result));
return $parsed_result;
} // function callAPI($data)
そして...機能しません....エラーは
PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML
手動で関数に $url を追加すると...それは彼の仕事をします:
function callAPI($data) {
global $username, $password, $url;
$url = 'http://api.xxxxxx.com';
$data['username'] = $username;
$data['password'] = $password;
$data['output'] = 'XML';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$result = curl_exec($ch);
curl_close ($ch);
$parsed_result = new SimpleXMLElement(str_replace('&','&',$result));
return $parsed_result;
} // function callAPI($data)
$url を追加すると Web サーバーが応答するため、$username と $password が正しい値で満たされていることは明らかです。したがって、「url」値に問題が1つだけあると思われます。
問題を解決する必要があります。関数「callAPI」では、$url が空白です。ピースの最初の部分で、$params->get $url の後、私の URL で正しくいっぱいになりました。
ありがとうございました