YII+DWZ三级城市联动挂件
2024-10-19 07:33:31
挂件PHP文件
class CountryCityCombox extends RXWidget {
public $provinceId = 2;
public $cityId = 3687;
public $regionId = 64;
public $level = 3; //限定联动层级 为2说明是2级联动 public function init() {
$this->provinceId = intval ( $this->provinceId );
$this->cityId = intval ( $this->cityId );
$this->regionId = intval ( $this->regionId );
$this->level = intval( $this->level );
} public function run() {
$province = Area::model ()->province()->findAll ();
$province = CHtml::listData ( $province, 'id', 'name' ); $city = array ();
if($this->provinceId) {
// city record
$cri = new CDbCriteria ();
$cri->condition = 'pid=:pid';
$cri->params = array (
':pid' => $this->provinceId
);
$city = Area::model ()->findAll ( $cri ); $city = CHtml::listData ( $city, 'id', 'name' );
} $region = array ();
if($this->cityId) {
//init region
// city record
$cri = new CDbCriteria ();
$cri->condition = 'pid=:pid';
$cri->params = array (
':pid' => $this->cityId
);
$region = Area::model ()->findAll ( $cri ); $region = CHtml::listData ( $region, 'id', 'name' );
} $views = array();
$views['ccc_province'] = array (0 => '请选择省') + $province;
$views['ccc_provinceId'] = $this->provinceId;
$views['ccc_city'] = array (0 => '选择城市') + $city;
$views['ccc_cityId'] = $this->cityId ;
if ($this->level != 2) {
$views['ccc_region'] = array (0 => '选择区') + $region;
$views['ccc_regionId'] = $this->regionId ;
}
$views['level'] = $this->level; $this->render ( 'countrycitycombox', $views); }
}
挂件视图文件
<label>选择地区:</label> <?php
$t = time () . uniqid ();
$htmlOptions = array (
'class' => 'combox',
'ref' => 'combox_city' . $t,
'refUrl' => 'area/get?id={value}',
'id' => 'provinceId' . $t
); echo CHtml::DropDownList ( 'provinceId', $ccc_provinceId, $ccc_province, $htmlOptions );
?> <?php
$htmlOptions = array (
'class' => 'combox',
'ref' => 'combox_region' . $t,
'refUrl' => 'area/get?id={value}',
'id' => 'combox_city' . $t
); echo CHtml::DropDownList ( 'cityId', $ccc_cityId, $ccc_city, $htmlOptions ); $htmlOptions = array (
'class' => 'combox',
'id' => 'combox_region' . $t
);
if ($level != 2) {
echo CHtml::DropDownList ( 'regionId', $ccc_regionId, $ccc_region, $htmlOptions );
}
挂件视图调用
一.2级联动
$widget=$this->Widget('CountryCityCombox',array(
'level'=>2
));
二.3级联动
$widget=$this->Widget('CountryCityCombox');
最新文章
- java5
- java 启动 shell脚本
- Linux下面配置文件~/.bash_profile
- KnockoutJS 3.X API 第四章 表单绑定(12) selectedOptions、uniqueName绑定
- C#构造Http 破解学校教务系统学生账号密码
- Hbase客户端API基础小结笔记(未完)
- JSP中的TAG
- Web Reference for a WCF Service has Extra “IdSpecified” Parameter ?
- 【转】关于JVM CPU资源占用过高的问题排查
- MySQL子查询优化实例
- JS画几何图形之六【过直线外一点作垂线】
- 洛谷 [P2486] 染色
- git远程提交失败
- C# RSA加解密与验签,AES加解密,以及与JAVA平台的密文加解密
- Android 访问地址
- threading.local()源码分析
- python第一课——关于python的一些概念
- QHeaderView的点击和双击事件
- (25)HttpClient session
- Git-标签管理【转】