挂件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');

最新文章

  1. java5
  2. java 启动 shell脚本
  3. Linux下面配置文件~/.bash_profile
  4. KnockoutJS 3.X API 第四章 表单绑定(12) selectedOptions、uniqueName绑定
  5. C#构造Http 破解学校教务系统学生账号密码
  6. Hbase客户端API基础小结笔记(未完)
  7. JSP中的TAG
  8. Web Reference for a WCF Service has Extra “IdSpecified” Parameter ?
  9. 【转】关于JVM CPU资源占用过高的问题排查
  10. MySQL子查询优化实例
  11. JS画几何图形之六【过直线外一点作垂线】
  12. 洛谷 [P2486] 染色
  13. git远程提交失败
  14. C# RSA加解密与验签,AES加解密,以及与JAVA平台的密文加解密
  15. Android 访问地址
  16. threading.local()源码分析
  17. python第一课——关于python的一些概念
  18. QHeaderView的点击和双击事件
  19. (25)HttpClient session
  20. Git-标签管理【转】

热门文章

  1. 【ORACLE】Bulk Processing with BULK COLLECT and FORALL
  2. js中的正则表达式【常用】
  3. 《LeetBook》leetcode题解(14):Longest Common Prefix[E]
  4. UUID 压缩为22位
  5. webpack初识!
  6. [转]NancyFx/Nancy
  7. WCF-异步调用和两种客户端形式
  8. Apache mod_rewrite
  9. Timer控件
  10. 一键LNMP文件