Menu that does not take me ajax

1

I have a problem with a dependent menu made with the YII framework, what I need is that when I enter a value in a dropdown and change another two dropdown, but it only takes me a few.

this is my controller:

public function actionAjaxListadoEdificio()
{
    if (Yii::app()->request->isAjaxRequest) {
        if (isset($_POST['id_establecimiento'])) {
            $idEstablecimiento = $_POST['id_establecimiento'];
            echo CHtml::tag('option', array('value' => ''), 'Todos');
            $edificios = Edificio::model()->findAll('id_establecimiento =:establecimiento', array(':establecimiento' => $idEstablecimiento));        

            foreach($edificios as $edificio) 
            { 
                $resultado = CHtml::tag('option', array('value' => $edificio->id), CHtml::encode($edificio->nombre)); 
                echo CJSON::encode(array(
                    'resultado'=>$resultado,
                ));
            }


        }
    }
}

   public function actionAjaxListadoDepartamentos(){
    if(Yii::app()->request->isAjaxRequest){
        if(isset($_POST['id_establecimiento'])){
            $idEdificio = $_POST['id_establecimiento'];
            echo CHtml::tag('option', array('value' => ''), 'Todos');
            $departamentos = Departamento::model()->findAll('id_establecimiento =:establecimiento' ,array(':establecimiento' => $idEdificio));

            foreach ($departamentos as $departamento){
                $resultado = CHtml::tag('option', array('value' => $departamento->id), CHtml::encode($departamento->nombre));
                echo CJSON::encode(array('resultado'=>$resultado));
            }
        }
    }
}

And this is my view:

array(
                            'name' => 'id_establecimiento',
                            'value' => '$data->establecimiento->nombre',             
                            'filter' => CHtml::activeDropDownList($model, 'id_establecimiento', CHtml::listData($establecimiento, 'id', 'nombre'), 
                                    array('empty' => 'Todos',
                                        'ajax' => array(
                                                        'type' => 'POST',
                                                        'url' => CController::createUrl('equipo/ajaxListadoEdificio'),
                                                        'data' => 
 array('id_establecimiento' => 'js:this.value'),
                                                        'update' => '#Equipo_id_edificio',
                                        ),
                                        'ajax' => array(
                                                        'type' => 'POST',
                                                        'url' => CController::createUrl('equipo/ajaxListadoDepartamentos'),
                                                        'data' => array('id_establecimiento' => 'js:this.value'),
                                                        'update' => '#Equipo_id_departamento' 
                                                    ))),
                        ),

(the model does not influence so that's why I do not place it)

    
asked by Mr.Manutri 04.04.2018 в 20:20
source

0 answers