LocationModel Location 地區(qū)信息服務(wù)模塊類
?? 要使用 Azalea\LocationModel 必須在配置中聲明使用
$config['node-beauty']['location'] = 1
?? LocationModel 構(gòu)造函數(shù)已私有,無(wú)法通過(guò) new 方式實(shí)例化,僅通過(guò) 控制器 或 模塊 的
getModel
方法獲得
// in controller-action
$locationModel = $this->getModel('location');
$info = $locationModel->ip(); // get current ip info
LocationModel::get
獲取地區(qū)信息
array LocationModel::get ( string ...$id )
參數(shù)
$id - 地區(qū)代碼,可一次傳入多個(gè)地區(qū)代碼返回值
地區(qū)信息數(shù)組范例
$result = $locationModel->get('440106', '440100', '000000');
// 返回
[
'000000' => null, // 不存在返回 null
'440100' => [
'name' => '廣州市',
'fullname' => '廣東省廣州市'
'post' => '',
'tele' => '',
],
'440106' => [
'name' => '天河區(qū)',
'fullname' => '廣東省廣州市天河區(qū)',
'post' => '510000',
'tele' => '020',
]
]
LocationModel::children
獲取下級(jí)地區(qū)
array LocationModel::children ( string $id = null )
參數(shù)
$id - 地區(qū)代碼,默認(rèn)為null
,即返回省份列表返回值
子地區(qū)數(shù)組范例
$result = $locationModel->children();
// 返回
[
'110000' => '北京市',
'120000' => '天津市',
...
'810000' => '香港特別行政區(qū)',
'820000' => '澳門特別行政區(qū)'
]
$result = $locationModel->children('440100');
// 返回
[
'440101' => '市轄區(qū)',
'440102' => '東山區(qū)',
...
'440183' => '增城市',
'440184' => '從化市'
]
LocationModel::ip
獲取 IP 信息
array LocationModel::ip ( string $ip = null )
參數(shù)
$ip - IP,默認(rèn)為 當(dāng)前 IP 地址返回值
IP 信息范例
$result = $locationModel->ip(); // 返回當(dāng)前 IP 信息
$result = $locationModel->ip('183.61.215.98');
// 返回
[
'int' => '3074283362',
'ip' => '183.61.215.98',
'country' => '廣東省廣州市',
'area' => '電信',
'province' => '440000'
]