<div class="select-wrap"> <?php echo $form->dropDownList($model, 'country_id', CHtml::listData(Country::model()->findAllByPk(3159), 'id', 'name')); ?> </div> <?php echo $form->error($model, 'country_id'); ?> </div> <div class="enter-form-row data-header"> <?php echo $form->labelEx($model, 'region_id'); ?> <div class="select-wrap"> <?php echo $form->dropDownList($model, 'region_id', $model->isNewRecord ? array('' => '') : CHtml::listData(Region::items($model->country_id), 'id', 'value')); ?> </div> <?php echo $form->error($model, 'region_id'); ?> </div> <div class="enter-form-row data-header"> <?php echo $form->labelEx($model, 'city_id'); ?> <div class="select-wrap"> <?php echo $form->dropDownList($model, 'city_id', $model->isNewRecord ? array('' => '') : CHtml::listData(City::items($model->region_id), 'id', 'value')); ?> </div>
public function action_ajax() { $r = Yii::app()->request; $c = $this->config; switch ($r->getParam('action')) { case 'getRegions': echo json_encode(Region::items($r->getParam('country_id'))); break; case 'getCities': echo json_encode(City::items($r->getParam('region_id'))); break; default: echo json_encode(null); break; } }