Listas Enlazadas

De KumbiaPHP Framework Wiki

Controlador

<?php
 class DatosController extends AdminController {

    protected function after_filter() {
        if (Input::isAjax()) {
            View::select('ajax', null);
        }
    }

    function index() {
    }

    function ciudades($id) {
        header('Content-type:text/json');
        $salida = array();
        $ciudades = Load::model('ciudades')->find_all_by_estados_id($id);
        foreach ($ciudades as $c) {
            $salida[$c->id] = $c->ciudad;
        }
        die(json_encode($salida));
    }
}

Modelos

ciudades.php

<?php
class Ciudades extends ActiveRecord {

}?>

estados.php

<?php
class Estados extends ActiveRecord {

}?>

Vista

<label for="datos_estados_id">Estado: </label> <?php echo Form::dbSelect('datos.estados_id', NULL, NULL, 'Elija', 'data-kumbia="remote" data-url="datos/ciudades" data-update="datos_ciudades_id"');?> <label class="control-label" for="datos_ciudades_id">Ciudad: </label> <?php echo Form::dbSelect('datos.ciudades_id'); ?>

<?php echo Tag::js('jquery/jquery.min'); ?> <?php echo Tag::js('jquery/kumbia.jquery.min'); ?>


By: ashrey