<div class="row">
<?php echo $form->labelEx($model_estado,'uf'); ?>
<?php
echo $form->dropDownList($model_estado,'uf',$this->getEstados(),
array(
'options'=>array($model_estado->id=>array('selected'=>'selected')),
'empty'=>'Selecione...',
'ajax' =>
array(
'type'=>'POST', //request type
'url'=>CController::createUrl('getCidadesDoEstado'), //action to call
'update'=>'#Endereco_cidade', // which HTML element to update
)
)
);
?>
<?php echo $form->error($model_estado,'uf'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model_endereco,'cidade'); ?>
<?php
echo CHtml::dropDownList(CHtml::activeName($model_endereco, 'cidade'),'',array(), array(
'empty'=>'Selecione...',
'id'=>'Endereco_cidade',
)
);
?>
<?php echo $form->error($model_endereco,'cidade'); ?>
</div>
public function actionGetCidadesDoEstado(){
$idEstado=$_POST['Estado'];
$listaDeCidades = Cidade::model()->findAllByAttributes(array('estado'=>(int)$idEstado),array('order'=>'nome'));
echo CHtml::tag(
'option', // tagname
array('value'=>''), // html params of tag
'Selecione...', // value from the item selected in the first dropdown is in the POST array
true // close tag
);
foreach ($listaDeCidades as $cidade){
echo CHtml::tag(
'option', // tagname
array('value'=>$cidade->id), // html params of tag
$cidade->nome, // value from the item selected in the first dropdown is in the POST array
true // close tag
);
}
}
How can i get a list of cities of the country $model_estado->id and how can I select the id of the model_cidade in a dropdown?