我按照 wiki 中给出的说明在 yii 中创建动态下拉列表,但仍然没有生成第二个下拉列表,这是我的视图文件:
echo CHtml::dropDownList('AccountTypeID','', array(1=>'Admin',2=>'Manager',3=>'Business',4=>'Finance',5=>'Customer Support'),array('ajax' => array('type'=>'POST',
'url'=>CController::createUrl('currentController/dynamiccities'), //url to call.
'update'=>'#city_id', //selector to update
)));
echo CHtml::dropDownList('city_id','', array());
这是我的控制器:
public function actionDynamiccities(){
$data= RefAccountgroup::model()->findAll('parent_id=:parent_id',
array(':parent_id'=>(int) $_POST['AccountTypeID']));
$data=CHtml::listData($data,'AccountGroupID','AccountGroupName');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}}