yii2-sypexgeo

Yii2 extension for Sypex Geo API (http://sypexgeo.net)

  • 所有者: omnilight/yii2-sypexgeo
  • 平台:
  • 许可证: BSD 3-Clause "New" or "Revised" License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Yii2 extension for Sypex Geo API (http://sypexgeo.net)

This extension adds support for Sypex Geo to the Yii2 framework

Note: This is not the fork of the JiSoft/yii2-sypexgeo!

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist omnilight/yii2-sypexgeo "*"

or add

"omnilight/yii2-sypexgeo": "*"

to the require section of your composer.json.

What it is all about?

Sypex Geo - product for location by IP address. Obtaining the IP address, Sypex Geo outputs information about
the location of the visitor - country, region, city, geographical coordinates and other in Russian and in English.
Sypex Geo use local compact binary database file and works very quickly.
For more information visit: http://sypexgeo.net/

This is extension for Yii2 framework that makes it easy to deal with Sypex Geo.

Usage

Unfortunately original version of Sypex Geo does not support Composer installation, so we have to include it into
this extension.

First of all, you have to download desired database from the http://sypexgeo.net/ website and place it somewhere
on your server.

There are two classes in this extension.

Sypexgeo - this is the component that can be used to retrive Geo information based on IP address. This component
incapsulates calls to the SxGeo methods.

You can use it as an application component:

// config.php
[
    'components' => [
        'sypexGeo' => [
            'class' => 'omnilight\sypexgeo\SypexGeo',
            'database' => '@app/data/SxGeoCity.dat',
        ]
    ]
]

// somewhere in your code
$city = Yii::$app->sypexGeo->getCity($ip);

Also you can create instance by yourself:


$sypexGeo = new omnilight\sypexgeo\Sypexgeo([
    'database' => '@app/data/SxGeoCity.dat',
]);
$city = $sypexGeo->getCity($ip);

GeoBehavior - behavior that can be attached to the yii\web\Request or it's children and this class adds methods
to simplify getting Geo information for current request.

Example:

// config.php
[
    'components' => [
        'request' => [
            'as sypexGeo' => [
                'class' => 'omnilight\sypexgeo\GeoBehavior',
                // It is not required to define property sypexGeo if you have sypexGeo component defined
                // in your application
                'sypexGeo' => [
                    'database' => '@app/data/SxGeoCity.dat',
                ]
            ]
        ]
    ],
]

// In your code
$city = Yii::$app->request->getCity();

主要指标

概览
名称与所有者omnilight/yii2-sypexgeo
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证BSD 3-Clause "New" or "Revised" License
所有者活动
创建于2014-10-24 08:28:35
推送于2021-11-01 15:43:36
最后一次提交2014-12-02 16:55:50
发布数1
最新版本名称1.0.0 (发布于 )
第一版名称1.0.0 (发布于 )
用户参与
星数17
关注者数3
派生数9
提交数6
已启用问题?
问题数0
打开的问题数0
拉请求数0
打开的拉请求数1
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?