pantera-digital/yii2-geo-location

该软件包最新版本(dev-master)没有可用的许可证信息。

Yii2 地理位置模块

安装: 277

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 4

分支: 0

开放问题: 0

类型:yii2-extension

dev-master 2018-11-29 02:26 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:42:05 UTC


README

geo-location

安装

首先需要安装和配置 https://github.com/himiklab/yii2-ipgeobase-component

composer require pantera-digital/yii2-geo-location "@dev"

配置

在控制台配置文件中添加迁移路径

'controllerMap' => [
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationPath' => [
            '@vendor/pantera-digital/yii2-geo-location/migrations',
        ],
    ],
],

添加到配置文件

'components' => [
    'geolocation' => [
        'class' => pantera\geolocation\components\Geolocation::className(),
    ],
    'ipgeobase' => [
        'class' => 'himiklab\ipgeobase\IpGeoBase',
        'useLocalDB' => true,
    ],
],
'modules' => [
    'geolocation' => [
        'class' => pantera\geolocation\Module::className(),
    ],
],

可以在 geobase_city_popular 表中添加默认城市

使用

插入小部件

<?= \pantera\geolocation\widgets\geolocation\Geolocation::widget() ?>

确定城市

Yii::$app->geolocation->identify()

根据id设置选择的城市

Yii::$app->geolocation->set($id)

获取选择的城市

Yii::$app->geolocation->get()