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.
Requirements:
- PHP 5.3
- Zend Framework 2
- An active internet connection (module fetches forecast from Google)
See https://github.com/artur-gajewski/GoogleWeather
Follow me on twitter: @GajewskiArtur
Go to your project directory and add the following line to "require" list in composer.json file:
"artur-gajewski/google-weather": "dev-master"
Now run the Composer:
php composer.phar install
Then add 'GoogleWeather' into the Module array in APPLICATION_ROOT/config/application.config.php
<?php
return array(
'modules' => array(
...
'GoogleWeather',
...
),
);
GoogleWeather module is accessible via Service Locator:
$weather = $this->getServiceLocator()->get('GoogleWeather');
When you obtain the service and create the object, you can then use it to do the magic:
$forecast = $weather->getWeather('Helsinki', 'en');
The return value is an object containing current and future weather information.
You can access forecast information with following functions:
Get the name of the forecast's location.
Get the current weather condition in selected language.
Get the URL to the image representing the current weather.
Get the current temperature in local degrees and type (celcius or fahrenheit).
Get the forecasted weather condition in selected language for the given day in array, 0 being today.
Get the forecasted weather image for the given day in array, 0 being today.
Get the string representation of day of the week for the given day in array, 0 being today.
Get the lowest forecasted temperature in local degrees and type for the given day in array, 0 being today.
Get the highest forecasted temperature in local degrees and type for the given day in array, 0 being today.
You can use GoogleWeather in your view scripts by using a view helper class provided.
<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>
Feel free to email me with any questions or comments about this module