public function actionLoadregion()
{
$data=Region::model()->findAll('countryId=:id',
array(':id'=>$_POST['Country']));
$data=CHtml::listData($data,'regionId','region');
echo "<option value=''>Select Region</option>";
foreach($data as $value=>$regio)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($regio),true);
}
کد view
echo CHtml::dropDownList('Country','',
CHtml::listData(Country::model()->findAll(),'countryId','country'),
array(
'prompt'=>'Select Country',
'ajax' => array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('loadregion'), //or $this->createUrl('loadcities') if '$this' extends CController
'update'=>'#Region', //or 'success' => 'function(data){...handle the data in the way you want...}',
'data'=>array('regionId'=>'js:this.value'),
)));
echo CHtml::dropDownList('Region','', array(), array('prompt'=>'Select Region'));
برچسب:
نویسنده: خنجی