页面View中
控制器Controller中
参考:http://www.jems.me/blog/web/84-yii-create-dropdown-lists-for-related-ar.html
<?php echo $form->dropdownList($model,"code", array('1'=>'1','2'=>'2','3'=>'3',),
array(
'ajax'=>array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('maillist/dynamicData'),
'update'=>'#update_id',
),
)
) ;?>
<?php echo CHtml::dropDownList('update_id','', array()); ?>
控制器Controller中
public function actiondynamicData(){
if (isset($_POST['Form'])) {
$data = CodeModel::model()->findAll(" code =:code and status = '1' ",
array(
":code" => trim($_POST['Form']['code']) ,
));
if (!is_null($data)){
foreach($values as $value){
echo CHtml::tag('option', array('value'=>$value['id']), CHtml::encode($value['name']), true);
}
}
}
}
参考:http://www.jems.me/blog/web/84-yii-create-dropdown-lists-for-related-ar.html