Download the PHP package youvision/think-regions without Composer

On this page you can find all versions of the php package youvision/think-regions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package think-regions

ThinkPHP-PanGu - 盘古ThinkPHP开源索引!

面向 ThinkPHP 的开源工程索引:组件、框架、服务与发布工具,按能力组织,持续整理。 仓库地址:https://github.com/indiboy-create/ThinkPHP-PanGu/ 在线站点:https://indiboy-create.github.io/ThinkPHP-PanGu/

youvision/think-regions

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

使用模型查询、服务注册、自动路由与独立安装命令,支持中文名称、拼音、首字母搜索。

特性

环境要求

安装

服务通过 Composer 的 extra.think.services 声明。若项目配置了 service:discover,安装后会自动注册;也可手动执行:

初始化数据

一键安装(推荐)

包内已内置 data/regions.csv,可直接执行安装;也可通过 csv_file、csv_url、--file 或 --url 指定其他数据源。

该命令会:

  1. 检查数据表是否存在,不存在时自动创建;
  2. 表内没有数据时,优先使用 --file、--url、csv_file、csv_url,均未指定时使用包内 data/regions.csv;
  3. 表内已有数据时停止导入,避免误覆盖。

常用参数:

CSV 首行建议包含表头,支持 id、pid、deep、name、pinyin_prefix、pinyin、ext_id、ext_name;也兼容旧字段名与无表头解析。编码支持 UTF-8 与 GBK。

配置

包内默认配置会在服务注册时自动合并,无需发布即可使用。需要修改默认值时:

配置文件会发布到项目 config/regions.php。目标文件已存在时跳过,追加 --force 可覆盖。

配置项 类型 默认值 说明
table string regions 数据表名,不含数据库前缀
connection string '' 数据库连接标识,留空使用默认连接
field string id,name,parent_id,level 列表查询返回字段
order string adcode asc,id asc 查询排序
cache int\|false 86400 查询缓存秒数,false 关闭
cache_key string think-regions 查询缓存键前缀
search_fields array ['name','pinyin_prefix','pinyin','ext_name'] 关键字搜索字段,支持 CSV 字段名
max_level int 4 数据最大层级
level_names array 省/市/区县/街道 层级名称映射
route bool true 是否自动注册路由
route_prefix string regions 自动路由前缀
route_middleware array [] 自动路由中间件
csv_url string '' 远程 CSV 下载地址,为空时使用包内数据
csv_file string '' 本地 CSV 文件,非空时优先于 csv_url
chunk_size int 500 批量写入条数

以上配置均已在实际查询、建表、导入和路由注册流程中生效;getPath() 与 getAddress() 会自动使用必要字段,不受 field 限制。

路由

开启 route 后,服务会自动注册以下接口,默认前缀为 /regions,同时响应 GET 与 POST 请求:

地址 参数 说明
/regions/getRegion parent_id,默认 0 获取指定父级下的地区,0 返回省份
/regions/getProvince 无 获取省份
/regions/getCity parent_id 获取城市
/regions/getDistrict parent_id 获取区(县)
/regions/getStreet parent_id 获取街道
/regions/searchRegion keywords、parent_id 搜索地区
/regions/searchProvince keywords 搜索省份
/regions/searchCity keywords、parent_id 搜索城市
/regions/searchDistrict keywords、parent_id 搜索区(县)
/regions/searchStreet keywords、parent_id 搜索街道
/regions/getById id 根据主键获取单条地区
/regions/getByAdcode adcode 根据行政区划编码获取单条地区
/regions/getPath id 获取从省份到当前地区的路径
/regions/getAddress id、separator 获取完整地址名称

返回值为 JSON 数组,例如:

手动注册路由

关闭自动路由:

然后在路由文件中自行注册:

门面

依赖注入

直接实例化

数据格式

导入数据为 CSV,推荐使用以下格式:

字段映射:

兼容性:

多应用模式

在多应用模式下,自动路由会注册为全局路由,前缀为 /regions。如果多个应用需要独立接口,建议:

数据库与缓存说明

示例

examples/region.html 是基于 layui 的四级联动与关键字搜索示例,将文件放入项目 public 目录后访问,并按需修改接口前缀。

测试

测试使用 SQLite 内存数据库,覆盖逐级查询、中文/拼音/首字母搜索、路径与地址、配置项生效、本地 CSV 导入、编码与表头解析、建表与清空等场景。

许可

MIT


All versions of think-regions with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
topthink/framework Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package youvision/think-regions contains the following files

Loading the files please wait ...