PHPackages                             life2016/yii2-region-custom - 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. life2016/yii2-region-custom

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

life2016/yii2-region-custom
===========================

Yii2中国省市区三级联动

1.0(8y ago)09BSD-3-ClausePHP

Since Sep 7Pushed 8y ago1 watchersCompare

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

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

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

[](#yii2-region)

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

安装
--

[](#安装)

添加到你的composer.json文件

```
"life2016/yii2-region-custom": "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'=>\chenkby\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(\chenkby\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删除。

demo
----

[](#demo)

[![image](https://raw.githubusercontent.com/chenkby/yii2-region/master/demo.png)](https://raw.githubusercontent.com/chenkby/yii2-region/master/demo.png)

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

[](#yii2-region-custom)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

3215d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/96126fb674e49c89c16c8f6cf2c0fca53197b35ed04a77bc0a7f1a942d32fafe?d=identicon)[ran](/maintainers/ran)

---

Tags

yii2cityregionprovincedistrict

### Embed Badge

![Health badge](/badges/life2016-yii2-region-custom/health.svg)

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

PHPackages © 2026

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