PHPackages                             yii-diandi/yii2-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. yii-diandi/yii2-region

ActiveYii2-widget[Utility &amp; Helpers](/categories/utility)

yii-diandi/yii2-region
======================

Yii2中国省市区三级联动

1.0.1(5y ago)04864BSD-3-ClauseTSQL

Since Jul 8Pushed 5y ago1 watchersCompare

[ Source](https://github.com/yii-diandi/region)[ Packagist](https://packagist.org/packages/yii-diandi/yii2-region)[ RSS](/packages/yii-diandi-yii2-region/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (2)Used By (4)

yii2-region
===========

[](#yii2-region)

Yii2 中国省市区三级联动()

安装
--

[](#安装)

添加到你的composer.json文件

```
"diandi/yii2-region": "dev-master"

```

配置
--

[](#配置)

1、在地区的Model中添加以下方法

```
    public static function getRegion($parentId=0)
    {
        $result = static::find()->where(['parent_id'=>$parentId])->asArray()->all();
        return ArrayHelper::map($result, 'id', 'name');
    }
```

2、在controller中添加以下action

```
    public function actions()
    {
        $actions=parent::actions();
        $actions['get-region']=[
            'class'=>\diandi\region\RegionAction::className(),
            'model'=>\app\models\Region::className()
        ];
        return $actions;
    }
```

3、启用urlManager的enablePrettyUrl的，即隐藏index.php

使用
--

[](#使用)

```
$url=\yii\helpers\Url::toRoute(['get-region']);

echo $form->field($model, 'province')->widget(\diandi\region\Region::className(),[
    'model'=>$model,
    'url'=>$url,
    'province'=>[
        'attribute'=>'province',
        'items'=>Region::getRegion(),
        'options'=>['class'=>'form-control form-control-inline','prompt'=>'选择省份']
    ],
    'city'=>[
        'attribute'=>'city',
        'items'=>Region::getRegion($model['province']),
        'options'=>['class'=>'form-control form-control-inline','prompt'=>'选择城市']
    ],
    'district'=>[
        'attribute'=>'district',
        'items'=>Region::getRegion($model['city']),
        'options'=>['class'=>'form-control form-control-inline','prompt'=>'选择县/区']
    ]
]);
```

province为省份配置，可用的选项可以查看Html::dropdownList。如果不需要县/区，可以把district删除。

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

2180d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/46cef84bc40d75ea2a86c1746f139764841f3d133d34d951bf78ea39faffaa20?d=identicon)[wangchunsheng](/maintainers/wangchunsheng)

---

Top Contributors

[![yii-diandi](https://avatars.githubusercontent.com/u/34767187?v=4)](https://github.com/yii-diandi "yii-diandi (4 commits)")

---

Tags

yii2cityregionprovincedistrict

### Embed Badge

![Health badge](/badges/yii-diandi-yii2-region/health.svg)

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

PHPackages © 2026

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