Wallogit.com
2017 © Pedro PelĂĄez
Zend Framework geolocation
zf3-geolocation, (*1)
zend framework 3 geolocation, (*2)
1) Ajouter l'exigence suivante Ă votre fichier composer.json. Dans la section:"require", (*3)
composer require jenzri-nizar/zf3-geolocation v1.0
2) Ouvrez votre ligne de commande et exécutez, (*4)
composer update
Le module doit ĂȘtre enregistrĂ© dans config/modules.config.php, (*5)
'modules' => array(
'...',
'Zf3\Geolocation'
),
Copiez le fichier situé dans vendor\jenzri-nizar\zf3-geolocation\config\geoip.local.php à config/geoip.local.php, (*6)
Modifiez les paramĂštres dans le fichier config/geoip.local.php, (*7)
provider - Le nom du plug-in à utiliser (voir exemples @vendor/jenzri-nizar/zf3-geolocation/src/Service/plugins/); return_formats - Les formats de retour pris en charge par le plugin api_key - Si nécessaire, vous pouvez passer votre clé api.
Plugins sont des fichiers PHP simples, qui renvoie un tableau avec trois variables: - plugin_url :URL du service Web, avec trois balises spéciales:, (*8)
a) {{accepted_formats}}, (*9)
b) {{ip}}, (*10)
c) {{api_key}}, (*11)
Ces balises seront remplacées par leurs valeurs respectives., (*12)
accepted_formats : Un tableau avec les formats acceptables (exemple ['csv', 'php', 'json', 'xml']), (*13)
default_accepted_format : Chaßne avec le format de retour par défaut. (exemple "php"), (*14)
'http://www.geoplugin.net/{{accepted_formats}}.gp?ip={{ip}}',
'accepted_formats' => ['json', 'php', 'xml'],
'default_accepted_format' => 'php',
];
```
##Exemple
```php
public function geopipAction(){
$GeoIp=$this->GeoIp()->getInfo("87.98.187.238");
$Weather=$this->GeoIp()->GetWeather($GeoIp->geoplugin_latitude,$GeoIp->geoplugin_longitude,$GeoIp->geoplugin_currencyCode);
return new ViewModel(array("Weather"=>$Weather,"GeoIp"=>$GeoIp));
}
```
geopip.phtml
```php
geoplugin_currencyCode) && $GeoIp->geoplugin_currencyCode != 'USD' ) {
return '(' . $GeoIp->geoplugin_currencySymbol . round( ($amount * $GeoIp->geoplugin_currencyConverter),2) . ')';
}
return false;
}
?>
zf3-geolocation
, (*15)
geoplugin_countryName;?>
, (*16)
geoplugin_request}:
\n".
"City: {$GeoIp->geoplugin_city}
\n".
"Region: {$GeoIp->geoplugin_region}
\n".
"Area Code: {$GeoIp->geoplugin_areaCode}
\n".
"DMA Code: {$GeoIp->geoplugin_dmaCode}
\n".
"Country Name: {$GeoIp->geoplugin_countryName}
\n".
"Country Code: {$GeoIp->geoplugin_countryCode}
\n".
"Longitude: {$GeoIp->geoplugin_longitude}
\n".
"Latitude: {$GeoIp->geoplugin_latitude}
\n".
"Currency Code: {$GeoIp->geoplugin_currencyCode}
\n".
"Currency Symbol: {$GeoIp->geoplugin_currencySymbol}
\n".
"Exchange Rate: {$GeoIp->geoplugin_currencyConverter}
\n";
?>, (*17)
Product A costs $800 ' . cc(800,$GeoIp) . ''; ?>, (*18)
, (*19)