hestec/silverstripe-ratingcomments

评论和评价

安装: 24

依赖: 0

建议者: 0

安全性: 0

类型:hestec-vendormodule

2.0.1 2024-02-16 15:25 UTC

This package is auto-updated.

Last update: 2024-09-16 16:49:14 UTC


README

通过使用OpenWeatherMap免费版本(https://openweathermap.org/)的数据,为您的SilverStripe网站添加一个简单的1到5天的天气预报。这个免费版本只提供5天/3小时的预报,但这个模块将收集的数据转换成1到5天的全天预报。目前它只是一个简单的预报,包含天气图标和最低最高温度。

要求

  • SilverStripe 4
  • cmfcmf/openweathermap-php-api

版本

使用语义版本。

安装

通过Composer安装

composer require "hestec/silverstripe-openweathermap": "1.*"

配置

https://openweathermap.org/注册(免费)账户并获取您的API密钥。

将OpenWeatherMap API密钥添加到您的yaml文件中

Hestec\OpenWeatherMap\OpenWeatherMapExtension:
  ApiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

执行dev/build并刷新。

工作状态

免费版本的OpenWeatherMap的预报数据(最多5天)将存储在OpenWeatherMapData表中,并在有人访问网站时每3小时更新一次。这种方法减少了API调用的次数,即使在OpenWeatherMap服务暂时不可用时也能显示天气。

使用方法

在您的页面中包含OpenWeatherMap

<% include OpenWeatherMap %>

这给出了里约热内卢市的5天天气预报。我想你想要其他城市的预报。为此,将模板\silverstripe-openweathermap\templates\Includes\OpenWeatherMap.ss复制到您的主题下的templates\Includes文件夹中,并更改循环调用的参数

<% loop WeatherForecast(5, 3451190) %>

这里的数字是预报天数(最多5天),代码是在OpenWeathetMap上使用的城市代码。在https://openweathermap.org/city获取您所在城市的代码:搜索城市名称,在URL中找到代码。

或者简单地将其循环放在您的页面中

<% loop WeatherForecast(5, 3451190) %>
       <p>$CityName, $CityCountry $Date:<br>
           Minimum temperatuur: $TemperatureMin<br>
           Maximum temperatuur: $TemperatureMax<br>
           <img src="$IconUrl">
       </p>
   <% end_loop %>

如果您想使用自己的图标而不是标准的OpenWeatherMap图标,请使用$Icon和图标路径。例如

<% loop WeatherForecast(5, 3451190) %>
       <p>$CityName, $CityCountry $Date:<br>
           Minimum temperatuur: $TemperatureMin<br>
           Maximum temperatuur: $TemperatureMax<br>
           <img src="/themes/simple/img/weather/$Icon\.png">
       </p>
   <% end_loop %>

在此处找到必要图标列表:https://openweathermap.org/weather-conditions

问题

无已知问题。

待办事项

  • 创建一个元素扩展。
  • 测试。
  • 更多预报类型(3小时预报,更多细节)。