You will need ajax anyway.
$form->dropDownList($model, $state, CHtml::listData(State::model()->findAll(),'id','state'), array(
'empty'=>"Select state",
'ajax' => array(
'type' => 'POST',
'url'=>$this->createUrl('registration/state'),
'update' => '#YOURcityID',
'data'=>array('state'=>'js:this.value',),
'success'=> 'function(data) {$("#YourcityID").empty();
$("#YourcityID").append(data);
} ',
)));
In yourcontroller:
public function actionState()
{
$data=Cities::model()->findAll('fk_id_state=:state',
array(':state'=> $_POST['state']));
$data=CHtml::listData($data,'city_id','city');
foreach($data as $value=>$city) {
echo CHtml::tag
('option', array('value'=>$value),CHtml::encode($city),true);
}
}
Back to form:
$form->dropDownlist($model, 'city', array(),array(
'empty'=>"Select city",
'ajax' => array(
'type' => 'POST',
'url'=>$this->createUrl('registration/city'),
'update' => '#YOURneighborhoodID',
'data'=>array('city'=>'js:this.value',),
'success'=> 'function(data) { $("#YourneighborhoodID").empty();
$("#YourneighborhoodID").append(data);
} ',
));
In controller:
public function actionCity()
{
$data=Neighborhood::model()->findAll('fk_id_city=:city',
array(':city'=> $_POST['city']));
$data=CHtml::listData($data,'neghborhood_id','neighborhood');
foreach($data as $value=>$neighborhood) {
echo CHtml::tag
('option', array('value'=>$value),CHtml::encode($neighborhood),true);
}
}
This will work like a charm. Check for typos and your variables cause i was hurry. Regards.