GoogleWeather module for Zend Framework 2
This module provides a way to obtain weather forecast for a given city and use view helper to display taht information on your view scripts., (*1)
Requirements:, (*2)
- PHP 5.3
- Zend Framework 2
- An active internet connection (module fetches forecast from Google)
See https://github.com/artur-gajewski/GoogleWeather, (*3)
Follow me on twitter: @GajewskiArtur, (*4)
Installation with Composer
Go to your project directory and add the following line to "require" list in composer.json file:, (*5)
"artur-gajewski/google-weather": "dev-master"
Now run the Composer:, (*6)
php composer.phar install
Then add 'GoogleWeather' into the Module array in APPLICATION_ROOT/config/application.config.php, (*7)
<?php
return array(
'modules' => array(
...
'GoogleWeather',
...
),
);
Accessing GoogleWeather from a controller
GoogleWeather module is accessible via Service Locator:, (*8)
$weather = $this->getServiceLocator()->get('GoogleWeather');
When you obtain the service and create the object, you can then use it to do the magic:, (*9)
$forecast = $weather->getWeather('Helsinki', 'en');
The return value is an object containing current and future weather information., (*10)
You can access forecast information with following functions:, (*11)
getLocation()
Get the name of the forecast's location., (*12)
getCurrentCondition()
Get the current weather condition in selected language., (*13)
getCurrentIcon()
Get the URL to the image representing the current weather., (*14)
getCurrentTemperature()
Get the current temperature in local degrees and type (celcius or fahrenheit)., (*15)
getForecastCondition($dayNumber)
Get the forecasted weather condition in selected language for the given day in array, 0 being today., (*16)
getForecastIcon($dayNumber)
Get the forecasted weather image for the given day in array, 0 being today., (*17)
getForecastDayOfWeek($dayNumber)
Get the string representation of day of the week for the given day in array, 0 being today., (*18)
getForecastLow($dayNumber)
Get the lowest forecasted temperature in local degrees and type for the given day in array, 0 being today., (*19)
getForecastHigh($dayNumber)
Get the highest forecasted temperature in local degrees and type for the given day in array, 0 being today., (*20)
Usage of GoogleWeather view helper
You can use GoogleWeather in your view scripts by using a view helper class provided., (*21)
getWeather('Helsinki')->getLocation(); ?>
<img src="<?php echo $this->getWeather('Helsinki')->getForecastIcon(0); ?>"/>
-
Week of day: getWeather('Helsinki')->getForecastDayOfWeek(0); ?>
-
Condition: getWeather('Helsinki')->getForecastCondition(0); ?>
-
Lowest temperature: getWeather('Helsinki')->getForecastLow(0); ?>
-
Highest temperature: getWeather('Helsinki')->getForecastHigh(0); ?>
Feel free to email me with any questions or comments about this module, (*22)
info@arturgajewski.com, (*23)