控制器
/**
* 获取所有省份
*/
public function getProv()
{
$data = $this->AreaModel->getProv();
self::_return($data);
}
/**
* 获取指定省份的城市
*/
public function getCity()
{
$id = $_POST['id'];
$data = $this->AreaModel->getCity($id);
self::_return($data);
}
/**
* 获取指定城市的区域
*/
public function getArea()
{
$id = $_POST['id'];
$data = $this->AreaModel->getArea($id);
self::_return($data);
}
模型
/**
* 获取所有省
*/
public function getProv()
{
$cols = '`provid`, `prov`';
$where = [];
$order = '`orderby` ASC';
return $this->table($this->prov)->cols($cols)->where($where)->order($order)->select()->fetchAll();
}
/**
* 获取指定省份的城市
*/
public function getCity($id)
{
$cols = '`cityid`, `city`';
$where = ['provid' => $id];
$order = '`orderby` ASC';
return $this->table($this->city)->cols($cols)->where($where)->order($order)->select()->fetchAll();
}
/**
* 获取指定城市的区域
*/
public function getArea($id)
{
$cols = '`areaid`, `area`';
$where = ['cityid' => $id];
$order = '`orderby` ASC';
return $this->table($this->area)->cols($cols)->where($where)->order($order)->select()->fetchAll();
}
表格
![](https://img-blog.csdnimg.cn/20201020181602689.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Z1amlhbjk1NDQ=,size_16,color_FFFFFF,t_70)