視圖文件 [html] <?php echo CHtml::activeDropDownList($model,'zmg_id',MemGroup::model()->getMemGroup(),array( 'class'=>'s_ipt w_120', 'empty'=>'請選擇會員組', 'ajax' =>array( 'type'=>'GET', 'url'=>CController::createUrl('cmpTemplates/getMemType'), 'update'=>'#CmpTemplates_zmg_ids', 'data'=>array('mid'=>"js:this.value") ), ))?> <?php echo $form->dropDownList($model,'zmg_ids',array(),array('class'=>'s_ipt w_120','empty'=>'選擇會員等級'))?> 控制器 [html] /** * 獲取會員組,對應的會員等級,用於下拉菜單 */ public function actionGetMemType($mid=0) { $criteria=new CDbCriteria; $criteria->compare('zmg_id',$mid); $memType = MemType::model()->findAll($criteria); $name = '選擇會員等級'; echo CHtml::tag('option', array('value'=>0), $name, true); foreach($memType as $val) { echo CHtml::tag('option', array('value'=>$val->zmt_id),CHtml::encode($val->zmt_title),true); } } 模型 [html] /* * 取會員組信息 */ public function getMemGroup($type=null){ if($type==null){ $criteria=new CDbCriteria; $criteria->compare('type','1'); $memGroup = MemGroup::model()->findAll($criteria); return CHtml::listData($memGroup,'zmg_id','zmg_title'); }else{ $level = $this->getMemGroup(); if(array_key_exists($type,$level)){ return $level[$type]; } } }