pianosolo/weather-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pianosolo/weather-bundle

最新稳定版本:v2.1.0

Composer 安装命令:

composer require pianosolo/weather-bundle

包简介

Weather Bundle of Symfony

README 文档

README

The PianoSolo Weather Bundle is a Symfony2 project to get data from weather services. Currently bringing data from OpenWeatherMap api. PianoSolo Weather Bundle has got different way of using the weather data in your project. One as a Twig Extension and the second one as a service which brings all weather information from api as object.

Latest Stable Version License Downloads

Installation

1-) Tell composer to download by running the command:

composer require pianosolo/weather-bundle

2-) Add the bundle to AppKernel

<?php
// app/AppKernel.php
	
public function registerBundles()
{
    $bundles = array(
        // ...
        new PianoSolo\WeatherBundle\PianoSoloWeatherBundle(),
    );
}

3-) Add configuration to config.yml file

piano_solo_weather:
    api_key: "YourApiKey" # Required (OpenWeatherMap Api Key)
    options:
        download_csv: false # Default True
        cache: true # Default False (To use cache the system needs Php-Apc cache)

To install Php-Apc rund this command:

sudo apt-get install php-apc

4-) Add the routing for CSV Downloading to routing.yml

pianosolo_weather:
    resource: "@PianoSoloWeatherBundle/Resources/config/routing.yml"

Usage

Basic Usage

Gets data from OpenWeatherMap api. Check api for usage: http://openweathermap.org/api

Get data with type. Add url parameters in array.

$weatherService = $this->get('pianosolo.weather');
$weather = $weatherService->getData('forecast', array('id' => 800, 'lat' => 52.52, 'lon' => 13.41));

Or get data with city name and type

$weatherService = $this->get('pianosolo.weather');
$weather = $weatherService->getCityData('weather', 'Berlin', array('param' => 'value'));
As Twig Extension

It brings the daily forecasts as html formatted in bootstrap table.

{{ pianosolo_get_forecast('Istanbul', 5) }}

This brings 5 days weather information of Istanbul ( Date, City, Temperature, Description )

{{ pianosolo_get_weather('Istanbul') }}

This brings 1 day of weather reasults of Istanbul ( Date, City, Temperature, Description )

As Weather Service

1-) Get weather response as stdclass object

$weatherService = $this->get('pianosolo.weather');
$weather = $weatherService->getWeather('Istanbul');

2-) Get weather as weather object

$weatherService = $this->get('pianosolo.weather');
$weathersArray = $weatherService->getWeatherObject('Istanbul');
$weatherObject = $weathersArray[0];
$city = $WeatherObject->getCity();
$date = $WeatherObject->getWdate();
$temperature = $WeatherObject->getTemperature();
$description = $WeatherObject->getDescription();

3-) Get forecast response as stdclass object

$weatherService = $this->get('pianosolo.weather');
$weather = $weatherService->getForecast('Istanbul', 2); // 2 days weather results of the city

4-) Get forecast as weather object array

$weatherService = $this->get('pianosolo.weather');
$weathersArray = $weatherService->getForecastObject('Istanbul',2);
foreach($weathersArray as $weatherObject){
	$city = $WeatherObject->getCity();
	$date = $WeatherObject->getWdate();
	$temperature = $WeatherObject->getTemperature();
	$description = $WeatherObject->getDescription();
	// Your Logic...
}

统计信息

  • 总下载量: 2.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-12