Ciao a tutti, nella sezione "Profilo" dei miei utenti devo far inserire i seguenti campi:
- 
Stato 
- 
Regione 
- 
Provincia 
- 
Comune 
Nel DB ho una tabella chiamata "stati", una "regione", etc… e nella tabella "profili" ho un campo per ognuno dove memorizzo il loro Id.
Ho creato una DropDownListGroup usando Yii Booster di questo tipo:
       $form = $this->beginWidget(
                                    'booster.widgets.TbActiveForm',
                                    array(
                                            'id' => 'horizontalForm',
                                            'type' => 'horizontal',
                                            'enableAjaxValidation'=>true,
                                            'action' => Yii::app()->createUrl('/profile/profile/update'),
                                        )
                                ); 
// STATO
           // retrieve the models from db
            $models = Stati::model()->findAll(
                                                    array('order' => 'nome__stati')
                                                );
            // format models as $key=>$value with listData
            $list = CHtml::listData($models,  'id', 'nome__stati');
            echo $form->dropDownListGroup(
                                            $profile,
                                            'stato',
                                            array(
                                                    'wrapperHtmlOptions' => array(
                                                                                    'class' => 'col-sm-5',
                                                                                    'style' => 'width:300px',
                                                                                ),
                                                    'widgetOptions' => array(
                                                                                //'data' => array('Something ...', '1', '2', '3', '4', '5'),
                                                                                'data' => $list,
                                                                                'htmlOptions' => array(),
                                                                            ),
                                                
                                                ),
                                            array(
                                                    
                                                    'ajax' => array(
                                                                    'type'=>'POST', //request type
                                                                    'url'=>CController::createUrl('/ajax/dynamicregion'), //url to call.
                                                                    //Style: CController::createUrl('currentController/methodToCall')
                                                                    'update'=>'#YumProfile_regione', //selector to update
                                                                    //'data'=>'js:javascript statement' 
                                                                    //leave out the data key to pass all form values through
                                                                ),    
                                                        )
                                        ); 
// REGIONE
            echo $form->dropDownListGroup(
                                            $profile,
                                            'regione',
                                            array()
                                        );
            
Poi ho fatto un AjaxController.php con questo codice
public function actionDynamicregion()
{
    $data=Regioni::model()->findAll('id_stato=:id_stato', array(':id_stato'=>(int) $_POST['YumProfile']['stato']));
    $data=Regioni::model()->findAll();
    $data=CHtml::listData($data,'id','regione');
    foreach($data as $value=>$name)
    {
        echo CHtml::tag('option',
                   array('value'=>$value),CHtml::encode($name),true);
    }
}
Facendo un po’ di copia-incolla con le soluzioni che trovavo su internet qua e là… Non ho capito bene in che punto va inserita la parte ajax nella dichiarazione della DropDownListGroup, non ho trovato 1 solo esempio. Ho fatto un po’ di prove senza successo.
L’unica cosa che funziona è che scelgo lo stato, viene memorizzato nel DB correttamente, ma non funziona la successiva chiamata al controller Ajax che dovrebbe popolarmi la seconda DropDown con le regioni.
Qualche idea o consiglio?
Grazie 1.000