Skip to content

A Zend Framework 2 module for fetching weather forecast provided by Google API.

Notifications You must be signed in to change notification settings

artur-gajewski/GoogleWeather

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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

Installation with Composer

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',
        ...
    ),
);

Accessing GoogleWeather from a controller

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:

getLocation()

Get the name of the forecast's location.

getCurrentCondition()

Get the current weather condition in selected language.

getCurrentIcon()

Get the URL to the image representing the current weather.

getCurrentTemperature()

Get the current temperature in local degrees and type (celcius or fahrenheit).

getForecastCondition($dayNumber)

Get the forecasted weather condition in selected language for the given day in array, 0 being today.

getForecastIcon($dayNumber)

Get the forecasted weather image for the given day in array, 0 being today.

getForecastDayOfWeek($dayNumber)

Get the string representation of day of the week for the given day in array, 0 being today.

getForecastLow($dayNumber)

Get the lowest forecasted temperature in local degrees and type for the given day in array, 0 being today.

getForecastHigh($dayNumber)

Get the highest forecasted temperature in local degrees and type for the given day in array, 0 being today.

Usage of GoogleWeather view helper

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>

Questions or comments?

Feel free to email me with any questions or comments about this module

[email protected]

About

A Zend Framework 2 module for fetching weather forecast provided by Google API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages