YII+DWZ三级城市联动挂件
挂件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');
YII+DWZ三级城市联动挂件的更多相关文章
- 全国三级城市联动 js版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- thinkPHP三级城市联动
html+js: <!doctype html> <html lang="en"> <head> <meta charset=" ...
- JQUERY省、市、县城市联动选择
JQUERY 插件开发——CITYLINKAGE(省.市.县城市联动选择) 第一部分:背景 开发源于需求,本次城市联动选择插件算是我写插件的一个特例吧,不是我目前工作需要些的,算是兴趣驱使吧.之前 ...
- JS中简单的二级城市联动
代码奉上: <!DOCTYPE html><html><head> <meta charset="UTF-8"> < ...
- Jquery 插件开发——citylinkage(省、市、县城市联动选择)
第一部分:背景 开发源于需求,本次城市联动选择插件算是我写插件的一个特例吧,不是我目前工作需要些的,算是兴趣驱使吧.之前呢,一直想写这个插件,然后错过了一个写这个插件的机会(这个得回顾到很久以前了. ...
- 城市联动 - 自动生成SQL语句
字段比较简单/ 如果有需要可以自己定制字段和排序/ 一共二级城市联动, 本人业务需要, 所以就两层, 网上关于三层的挺多, 有需要可以借鉴/ 废话不多说, 先看效果图, 代码在下面 <?php ...
- JQuery+Ajax实战三级下拉列表联动(八)
本片文章为练习,项目中不会这样写: 一:涉及到的知识点: jQuery Dom操作 jQuery Ajax操作 ASP.net中的json操作 二:用了自动代码生成器 1.Dal层的代码: publi ...
- java基础68 JavaScript城市联动框(网页知识)
1.城市联动框 <!doctype html> <html> <head> <meta charset="utf-8"> <t ...
- 基于jQuery+ashx+.net实现三级栏目联动操作
父级ID可以为空以两个编号为一级 可以添加到第四级 table 字段有ID. name .parentNode. childNode等基本属性 selecet parentNode ,len(c ...
随机推荐
- 1、 小白带你入坑xamarin系列之环境搭建和准备
重点提示 由于xamarin发展更新很快 目前教程部分内容已经过时 请注意下载最新版本 2018.05.23 www.xamarin.com 1. 小白带你入坑xamarin系列之环境搭建和准备 ...
- java翻译到mono C#实现系列(2) mono实现GridView 横向滚动
群里的朋友问GridView 横向滚动怎么实现,我就百度了,参考http://blog.csdn.net/lonely_fireworks/article/details/7841134写了个mono ...
- redux在componentDidMount中出现的问题 --- state 不变
遇到这样一个问题: 在组件的componentDidMount中,我需要使用到redux中存储的某个状态. 但是有趣的是,当我再render中使用相同的状态时,状态会改变,但是在conponentDi ...
- 全网最详细的Git学习系列之介绍各个Git图形客户端(Windows、Linux、Mac系统皆适用ing)(图文详解)
不多说,直接上干货! 一.TortoiseGit - The coolest Interface to Git Version Control TortoiseGit 是 TortoiseSVN 的 ...
- Volley 源码解析(转)
项目:Volley,分析者:grumoon,校对者:Trinea 本文为 Android 开源项目源码解析 中 Volley 部分项目地址:Volley,分析的版本:35ce778,Demo 地址:V ...
- JavaScript数据结构-1.数组
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MySQL之mysql命令使用详解
MySQL Name mysql - the MySQL command-line tool Synopsis mysql [options] db_name Description mysql is ...
- secret
## 概览 Secret是用来保存小片敏感数据的k8s资源,例如密码,token,或者秘钥.这类数据当然也可以存放在Pod或者镜像中,但是放在Secret中是为了更方便的控制如何使用数据,并减少暴露的 ...
- UVM序列篇之二:sequence和item(上)
无论是自驾item,穿过sequencer交通站,通往终点driver,还是坐上sequence的大巴,一路沿途观光,最终跟随导游停靠到风景点driver,在介绍如何驾驶item和sequence,遵 ...
- 分布式一致性协议介绍(Paxos、Raft)
两阶段提交 Two-phase Commit(2PC):保证一个事务跨越多个节点时保持 ACID 特性: 两类节点:协调者(Coordinator)和参与者(Participants),协调者只有一 ...