PHPackages                             yupoxiong/region - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. yupoxiong/region

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yupoxiong/region
================

ThinkPHP省市区(县)街道四级联动扩展

v1.1.5(2y ago)1032.9k↓50%221Apache-2.0PHPPHP &gt;=5.6

Since Nov 1Pushed 2y ago4 watchersCompare

[ Source](https://github.com/yupoxiong/region)[ Packagist](https://packagist.org/packages/yupoxiong/region)[ Docs](https://github.com/yupoxiong/region)[ RSS](/packages/yupoxiong-region/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)DependenciesVersions (10)Used By (1)

ThinkPHP省市区(县)街道四级联动扩展
======================

[](#thinkphp省市区县街道四级联动扩展)

[![](https://camo.githubusercontent.com/076bbfe66f73b8cef3b9d03b14d56b5af9a9b55c969fd2ed412d44ee09342a8f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d352e362d626c75652e737667)](https://github.com/yupoxiong/region)

> 支持 `TP5.0.*` 和 `TP5.1.*` 还有 `TP6.0` ，搜索功能支持汉字，支持拼音，首字母搜索。

#### 安装

[](#安装)

##### 第一步：安装扩展

[](#第一步安装扩展)

Composer 运行扩展安装命令

```
# TP数据库迁移工具
composer require topthink/think-migration
# 本扩展
composer require yupoxiong/region

```

##### 第二步：创建数据表

[](#第二步创建数据表)

复制`vendor/yupoxiong/region/database/migrations`目录下的数据库迁移文件到TP迁移目录(一般是 `/database/migrations/` )，然后运行TP自带迁移命令创建表。

> TP5.1 版本可以直接运行以下两个命令完成安装

```
php think region:publish

php think region:migrate

```

> TP6.0 版本可以直接运行以下命令完成安装

```
php think region:migrate

```

#### 添加路由

[](#添加路由)

TP5.0 在 `/application/route.php` 中追加，TP5.1 在 `/route/route.php` 中追加。

```
Route::alias('region','\yupoxiong\region\RegionController');

```

> TP6.0版本已经去掉别名路由，可以在路由配置里添加以下路由(多应用模式在应用路由里添加)：

```
Route::group('region',function (){
    Route::any('getRegion','\yupoxiong\region\RegionController@getRegion');
    Route::any('getProvince','\yupoxiong\region\RegionController@getProvince');
    Route::any('getCity','\yupoxiong\region\RegionController@getCity');
    Route::any('getDistrict','\yupoxiong\region\RegionController@getDistrict');
    Route::any('getStreet','\yupoxiong\region\RegionController@getStreet');
    Route::any('searchRegion','\yupoxiong\region\RegionController@searchRegion');
    Route::any('searchProvince','\yupoxiong\region\RegionController@searchProvince');
    Route::any('searchCity','\yupoxiong\region\RegionController@searchCity');
    Route::any('searchDistrict','\yupoxiong\region\RegionController@searchDistrict');
    Route::any('searchStreet','\yupoxiong\region\RegionController@searchStreet');
});
```

#### 使用

[](#使用)

##### 获取地区(最常用的方式)

[](#获取地区最常用的方式)

- url `/region/getRegion`
- 参数 parent\_id ，可不传(默认0)获取省份，传入上级 id 即可获取该 id 对应的下级

##### 获取省

[](#获取省)

- url `/region/getProvince`
- 参数 无

##### 获取市

[](#获取市)

- url `/region/getCity`
- 参数 parent\_id ，传入所属省 id 即可获取该省下面的市

##### 获取区

[](#获取区)

- url `/region/getDistrict`
- 参数 parent\_id ，传入所属市 id 即可获取该市下面的区(县)

##### 获取街道

[](#获取街道)

- url `/region/getStreet`
- 参数 parent\_id ，传入所属区(县) id 即可获取该市下面的街道

##### 搜索地区

[](#搜索地区)

- url `/region/searchRegion`
- 参数 keywords ，搜索地区的关键字
- 参数 parent\_id ，搜索地区的父级 id ，默认0为搜索省份

##### 搜索省

[](#搜索省)

- url `/region/searchProvince`
- 参数 keywords ，搜索地区的关键字

##### 搜索市

[](#搜索市)

- url `/region/searchCity`
- 参数 keywords ，搜索地区的关键字
- 参数 parent\_id ，所属省 id

##### 搜索区

[](#搜索区)

- url `/region/searchDistrict`
- 参数 keywords ，搜索地区的关键字
- 参数 parent\_id ，所属市 id

##### 搜索街道

[](#搜索街道)

- url `/region/searchStreet`
- 参数 keywords ，搜索街道的关键字
- 参数 parent\_id ，所属区(县) id

#### 可选配置

[](#可选配置)

可在配置文件中添加以下配置，5.0.\* 在 `/application/config.php` 中追加。

```
//获取省市区街道缓存、查询字段配置
'region' => [
    //查询缓存秒数，false为不缓存
    'cache' => 20140210,
    //查询字段，可选项：id,name,parent_id,initial,pinyin,citycode,adcode,lng_lat
    'field' => 'id,name',
    //排序，默认为adcode正序
    'order' => 'adcode asc',
]

```

> 5.1.\* 和 6.0 直接运行以下命令即可在 config 目录下生成 `region.php` 配置文件。

```
php think region:publish

```

#### Facade

[](#facade)

TP5.1 和 TP6.0 可以在开发中直接使用以下代码获取数据：

```
\yupoxiong\region\facade\Region::getProvince();
//更多可参考该类
```

#### 测试相关

[](#测试相关)

安装配置好之后可以将`vendor/yupoxiong/region/tests/region.html`放到项目`public`目录下访问测试扩展是否可用

[点此查看demo](https://demo.bearadmin.com/region.html)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~208 days

Recently: every ~358 days

Total

9

Last Release

1084d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/868c12363bbfd6e2a44cffde1763817c4422c94d968451e40076634007d66a40?d=identicon)[yupoxiong](/maintainers/yupoxiong)

---

Top Contributors

[![yupoxiong](https://avatars.githubusercontent.com/u/13145867?v=4)](https://github.com/yupoxiong "yupoxiong (28 commits)")

---

Tags

composer-librarythinkphp5regionthinkphp

### Embed Badge

![Health badge](/badges/yupoxiong-region/health.svg)

```
[![Health](https://phpackages.com/badges/yupoxiong-region/health.svg)](https://phpackages.com/packages/yupoxiong-region)
```

###  Alternatives

[ofcold/identity-card

A simple proof of identity card of the people's Republic of China.

18839.6k](/packages/ofcold-identity-card)[liliuwei/thinkphp-jump

适用于thinkphp6.0的跳转扩展

2874.4k1](/packages/liliuwei-thinkphp-jump)[xiaodi/think-pullword

ThinkPHP 分词/抽词 扩展包

5512.1k](/packages/xiaodi-think-pullword)[isszz/rotate-captcha

Rotate image captcha

801.7k](/packages/isszz-rotate-captcha)[xiaodi/think-pinyin

ThinkPHP 中文转拼音扩展包

344.6k](/packages/xiaodi-think-pinyin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
