sem-soft/yii2-ipgeobase

Yii2 组件,基于 http://ipgeobase.ru/ 地理位置服务

安装次数: 21

依赖者: 0

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

开放问题: 0

类型:yii2-components

1.0.3 2018-02-02 08:53 UTC

This package is auto-updated.

Last update: 2024-09-07 07:07:06 UTC


README

通过 composer 安装

composer require sem-soft/yii2-ipgeobase

使用本地地理数据库运行迁移

$ ./yii migrate/up --migrationPath=@vendor/sem-soft/yii2-ipgeobase/migrations

或者将以下代码添加到 composer.json 的 require 部分,然后在控制台中运行 composer update

"sem-soft/yii2-ipgeobase": "*"

用法

在配置文件中执行

<?php
...
  'components'  =>  [
    ...
    'geo'	=>  [
        'class' => \sem\ipgeobase\IpGeoBase::className(),
        'serviceTimeout' => 2
    ],
    ...
  ],
...
 ?>

作为简单组件使用

<?php
if ($g = Yii::$app->geo->geo) {
   echo $g->city;
}

if ($g = Yii::$app->geo->getGeo('86.XXX.YYY.ZZZ')) {
   echo $g->city;
}

if ($g = Yii::$app->geo->getCityInfo('Москва')) {
   echo $g->city;
}
?>