zoukankan      html  css  js  c++  java
  • 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');
    
  • 相关阅读:
    Java POI Word 写文档
    安装SQL Server Management Studio遇到的29506错误
    DataSet中的relation
    如何在Eclipse中配置Tomcat
    button与submit
    redis应用场景
    机器学习实战-KNN(K-近邻算法)详解
    python中的random扩展
    php函数实现文章列表显示的几秒前,几分钟前,几天前等方法
    HTML5的Video标签的属性,方法和事件汇总
  • 原文地址:https://www.cnblogs.com/darktime/p/DWZ.html
Copyright © 2011-2022 走看看