Please note that I made update of my post (part of the code got broken, it is fixed now …)
Please note that I made update of my post (part of the code got broken, it is fixed now …)
Finally done actually what I was looking for that is dependent dropdown list for create action as well as update action. I am explaining here how I solved:
in the form:
<div class="row">
<?php echo $form->labelEx($model,'service_site'); ?>
<?php echo $form->dropDownList($model,'service_site',$model->getSiteOptions(),
array(
'ajax' => array('type'=>'POST',
'url'=>$this->createUrl('servicePoint'), //url to call.
'update'=>'#'.CHtml::activeId($model, 'service_point'), //selector to update
'data'=>array('service_site'=>'js:this.value'),
)));
?>
<?php echo $form->error($model,'service_site'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'service_point'); ?>
<?php
if ($model->service_point === NULL) {
echo $form->dropDownList($model,'service_point',array(), array('prompt'=>'Select Points'));
} else {
echo $form->dropDownList($model,'service_point',$model->getSitePoints($model->service_site));
}
?>
<?php echo $form->error($model,'service_point'); ?>
</div>
in the controller:
public function actionServicePoint(){
// The following command does not work
$data=Sp::model()->findAll('site_id=:service_site',
array(':service_site'=>(int) $_POST['service_site']));
$data=CHtml::listData($data,'id','name');
foreach($data as $value=>$name) {
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
in the model:
public function getSiteOptions()
{
return array(
0=>'Select Site',
1=>'Kalihata , Tangail',
2=>'Bheramar , Kustia',
);
}
public function getSitePoints($siteId)
{
$data=Sp::model()->findAll('site_id=:Id',
array(':Id'=>(int) $siteId));
$data=CHtml::listData($data,'id','name');
return $data;
}
I pasted here who will be helped as me.
Many many thanks to Kalpit and Dulo who help me , guided me a lot.
see you
great…
I am happy it is working for you and I was of some help.