artur-gajewski / google-weather
该软件包最新版本(dev-master)没有提供许可信息。
此模块提供了一种获取指定城市天气预报的方法,并使用视图助手在视图脚本中显示这些信息。
dev-master
2012-09-27 05:34 UTC
Requires
- php: >=5.3.3
- zendframework/zendframework: dev-master
This package is not auto-updated.
Last update: 2024-09-14 11:44:45 UTC
README
此模块提供了一种获取指定城市天气预报的方法,并使用视图助手在视图脚本中显示这些信息。
要求
- PHP 5.3
- Zend Framework 2
- 有效的互联网连接(模块从Google获取预报)
查看 https://github.com/artur-gajewski/GoogleWeather
在twitter上关注我:@GajewskiArtur
使用Composer安装
转到您的项目目录,并在composer.json文件中的"require"列表中添加以下行
"artur-gajewski/google-weather": "dev-master"
现在运行Composer
php composer.phar install
然后,将'GoogleWeather'添加到APPLICATION_ROOT/config/application.config.php文件中的Module数组中
<?php return array( 'modules' => array( ... 'GoogleWeather', ... ), );
从控制器访问GoogleWeather
GoogleWeather模块可通过服务定位器访问
$weather = $this->getServiceLocator()->get('GoogleWeather');
当你获取服务并创建对象时,你可以使用它来完成这项工作
$forecast = $weather->getWeather('Helsinki', 'en');
返回值是一个包含当前和未来天气信息的对象。
你可以使用以下函数访问预报信息
getLocation()
获取预报位置的名称。
getCurrentCondition()
获取所选语言中的当前天气状况。
getCurrentIcon()
获取表示当前天气的图像的URL。
getCurrentTemperature()
获取以本地度数和类型(摄氏度或华氏度)表示的当前温度。
getForecastCondition($dayNumber)
以所选语言获取给定日期的预报天气状况,数组中的0代表今天。
getForecastIcon($dayNumber)
获取给定日期的预报天气图像,数组中的0代表今天。
getForecastDayOfWeek($dayNumber)
获取数组中给定日期的星期字符串表示,0代表今天。
getForecastLow($dayNumber)
获取数组中给定日期的最低预报温度,0代表今天。
getForecastHigh($dayNumber)
获取数组中给定日期的最高预报温度,0代表今天。
GoogleWeather视图助手的使用
您可以通过提供的视图助手类在视图脚本中使用GoogleWeather。
<h2> <?php echo $this->getWeather('Helsinki')->getLocation(); ?> </h2> <img src="<?php echo $this->getWeather('Helsinki')->getForecastIcon(0); ?>"/> <ul> <li> Week of day: <?php echo $this->getWeather('Helsinki')->getForecastDayOfWeek(0); ?> </li> <li> Condition: <?php echo $this->getWeather('Helsinki')->getForecastCondition(0); ?> </li> <li> Lowest temperature: <?php echo $this->getWeather('Helsinki')->getForecastLow(0); ?> </li> <li> Highest temperature: <?php echo $this->getWeather('Helsinki')->getForecastHigh(0); ?> </li> </ul>
有问题或评论吗?
请随时通过电子邮件向我提出有关此模块的任何问题或评论