Hi everyone,
i’m populating dropdownlist based on anther dropdownlist here is my view code:
<?php
echo $form->dropDownList($model,'menu_category_id',
CHtml::listData(MenuCategory::model()->findAll(), 'id', 'name'),
array(
'prompt'=>'Select Menu Category',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('GetMenuType'),
'update'=>'#menu_type_id',
'data'=>array('menu_category_id'=>'js:this.value'),
)));
echo $form->error($model,'menu_category_id');
echo '</div>';
echo '<div class="row">';
echo $form->labelEx($model,'menu_type_id');
// replace the live below
echo $form->dropDownList($model,'menu_type_id', array(), array('prompt'=>'Select Menu Type'));
?>
<?php echo $form->error($model,'menu_type_id'); ?>
above code works perfectly fine if i use this
echo CHtml::dropDownList(‘menu_type_id’,’’, array(), array(‘prompt’=>‘Select Menu Type’));
but when i add that array into $form->dropdownlist(… it doesn’t work
any help below is my controller code.
public function actionGetMenuType()
{
$models = MenuType::model()->findAll('menu_category_id=:menu_category_id',
array(':menu_category_id'=>$_POST['menu_category_id']));
$list = CHtml::listData($models, 'id', 'name');
echo "<option value=''>Select Menu Type</option>";
foreach($list as $id=>$name){
echo CHtml::tag('option',
array('value'=>$id), CHtml::encode($name), true);
}
}