Diferencia entre revisiones de «Listas Enlazadas»
De KumbiaPHP Framework Wiki
| Línea 1: | Línea 1: | ||
| + | == Controlador == | ||
| + | <code> | ||
| + | <?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)); | ||
| + | } | ||
| + | }</code> | ||
| + | |||
== Modelos == | == Modelos == | ||
'''ciudades.php''' <br /> | '''ciudades.php''' <br /> | ||
| Línea 24: | Línea 50: | ||
<?php echo Form::dbSelect('datos.ciudades_id'); ?> | <?php echo Form::dbSelect('datos.ciudades_id'); ?> | ||
</code> | </code> | ||
| + | |||
| + | <?php echo Tag::js('jquery/jquery.min'); ?> | ||
| + | <?php echo Tag::js('jquery/kumbia.jquery.min'); ?> | ||
By: '''ashrey''' | By: '''ashrey''' | ||
Revisión del 21:00 6 mar 2013
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