sem-soft/yii2-ipgeobase

Yii2 component geolocation http://ipgeobase.ru/ service

Installs: 21

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-components

1.0.3 2018-02-02 08:53 UTC

This package is auto-updated.

Last update: 2024-11-07 07:32:04 UTC


README

Install by composer

composer require sem-soft/yii2-ipgeobase

Run migrations with local geo DB

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

Or add this code into require section of your composer.json and then call composer update in console

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

Usage

In configuration file do

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

Use as simple component

<?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;
}
?>