最後に私はそれをやった、ここにある。
私のコントローラーでは、
public function actionDynamicDropdownList()
{
if($_POST['client_id'] > '0') {
$result = Yii::app()->db->createCommand()->select('program_id, program_name')->from('program')->where('client_id='.$_POST['client_id'].'')->order('program_name')->queryAll();
$this->render('admin', array(
'result' => $result,
));
}
}
public function actionDynamicProgramsList()
{
if($_POST['program_id'] > '0') {
$results = Yii::app()->db->createCommand()->select('ad_id, ad_name')->from('ads')->where('program_id='.$_POST['program_id'].'')->order('ad_name')->queryAll();
$this->render('admin', array(
'results' => $results,
));
}
}
そして私の見解では、私は追加しました
<?php
$data = Yii::app()->db->createCommand()->select('client_id, client_name')->from('client')->order('client_name')->queryAll();
echo CHtml::dropDownList('client_id', '',CHtml::listData($data,'client_id','client_name'), array(
'empty'=>'- Select Client Name -',
'ajax'=> array(
'type'=>'POST',
'url'=>Yii::app()->baseUrl.'/index.php?r=page/dynamicDropdownList',
'update'=>'#program_id')));
//empty since it will be filled by the above dropdown
echo CHtml::dropDownList('program_id','', CHtml::listData($result,'program_id','program_name'), array(
'empty'=>'- Select Program Name - ',
'onchange'=>'alert(this.value);',
'ajax'=> array(
'type'=>'POST',
'url'=>Yii::app()->baseUrl.'/index.php?r=page/dynamicProgramsList',
'update'=>'#ad_id')));
//empty since it will be filled by the above dropdown
echo CHtml::dropDownList('ad_id','', CHtml::listData($results,'ad_id','ad_name'), array(
'empty'=>'- Select Ad Name - ',
));
?>