我在 Yii+extjs 工作。我正在创建天气模块。我想从用户的 ipaddress 中检索天气信息。我从 website="http://www.geoplugin.com/examples" 获得了参考代码。正如那里提到的,我创建了getweather函数=
public function actionGetWeather()
{
$user_ip = $_SERVER['REMOTE_ADDR'];
//The Data Science Toolkit URL
$url = 'http://www.datasciencetoolkit.org/ip2coordinates/';
//Find the user's location from their IP.
//*** You need the get_data function from the sample code
$raw_geocode = json_decode( get_data( $url . $user_ip) );
//Check if the user is in the US
if ('US' === $raw_geocode->$user_ip->country_code) {
//If yes, store their zip code in a variable, and print it
$zip_code = $raw_geocode->$user_ip->postal_code;
printf('<p>Your zip code is: %s</p>', $raw_geocode->$user_ip->postal_code);
} else {
//If the user isn't in the US, set a sip code that will work.
$zip_code = '97211';
//and print an error
printf('<p>Sorry, this app does not work in %s.</p>', $raw_geocode->$user_ip->country_name);
}
//Print the raw data for debugging.
printf('<pre>%s</pre>', print_r($raw_geocode, true));
}
我也在我的项目中包含了 ParseXml 类。但上面的代码给出的错误是致命错误:在“$raw_geocode = json_decode(get_data($url.$user_ip));”行调用未定义函数 get_data() getweather 函数。那么我需要什么改变?请帮我