jenzri-nizar / zf3-geolocation
Zend Framework 地理定位
v1.0
2016-10-01 16:30 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-14 19:53:04 UTC
README
zf3-geolocation
zend framework 3 地理定位
##安装
- 将以下需求添加到您的composer.json文件中的"require"部分。
composer require jenzri-nizar/zf3-geolocation v1.0
- 打开您的命令行并执行
composer update
模块应在config/modules.config.php中注册
'modules' => array( '...', 'Zf3\Geolocation' ),
##配置
将位于vendor\jenzri-nizar\zf3-geolocation\config\geoip.local.php的文件复制到config/geoip.local.php
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.
插件
插件是简单的PHP文件,返回包含三个变量的数组
- plugin_url:Web服务的URL,包含三个特殊标记
a) {{accepted_formats}}
b) {{ip}}
c) {{api_key}}
这些标记将被它们各自的值替换。
-
accepted_formats:一个包含可接受格式的数组(例如 ['csv', 'php', 'json', 'xml'])
-
default_accepted_format:默认返回格式的字符串(例如 "php")
插件文件示例
<?php $plugin = [ 'plugin_url' => 'http://www.geoplugin.net/{{accepted_formats}}.gp?ip={{ip}}', 'accepted_formats' => ['json', 'php', 'xml'], 'default_accepted_format' => '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 function cc($amount,$GeoIp) { if ( isset($GeoIp->geoplugin_currencyCode) && $GeoIp->geoplugin_currencyCode != 'USD' ) { return '(' . $GeoIp->geoplugin_currencySymbol . round( ($amount * $GeoIp->geoplugin_currencyConverter),2) . ')'; } return false; } ?> <div class="jumbotron"> <h1>zf3-geolocation</span></h1> <p> <?php echo $Weather?> </p> <p> <?php echo 'Welcome to our visitors from '.$GeoIp->geoplugin_countryName;?> </p> <p> <?php echo "Geolocation results for {$GeoIp->geoplugin_request}: <br />\n". "City: {$GeoIp->geoplugin_city} <br />\n". "Region: {$GeoIp->geoplugin_region} <br />\n". "Area Code: {$GeoIp->geoplugin_areaCode} <br />\n". "DMA Code: {$GeoIp->geoplugin_dmaCode} <br />\n". "Country Name: {$GeoIp->geoplugin_countryName} <br />\n". "Country Code: {$GeoIp->geoplugin_countryCode} <br />\n". "Longitude: {$GeoIp->geoplugin_longitude} <br />\n". "Latitude: {$GeoIp->geoplugin_latitude} <br />\n". "Currency Code: {$GeoIp->geoplugin_currencyCode} <br />\n". "Currency Symbol: {$GeoIp->geoplugin_currencySymbol} <br />\n". "Exchange Rate: {$GeoIp->geoplugin_currencyConverter} <br />\n"; ?></p> <p><?php echo '<h3>Product A costs $800 ' . cc(800,$GeoIp) . '</h3>'; ?></p> </div>