I have code in CodeIgniter which takes a value of select dropbox
in a view
and leads to a second view
showing the results in a table. In that second view
, I kept the dropbox
and the submit
("Filter") button and would like the user to select another value from dropbox
and filter, reloading the page with other results to show in the table.
I did this, but the page is not reloading. I believe I should put something at the end of the URL to be different from every refresh or something, but for now without success. Any suggestions?
Model:
class TrackerModel extends CI_Model {
function get_coordenadas($cliente, $filtro, $num, $offset){
//SELECT * FROM 'tracker_coordenada','tracker_veiculo' WHERE tracker_coordenada.veiculo_codigo = tracker_veiculo.veiculo_codigo AND tracker_veiculo.cli_cod = $cliente
$this->db->select('tracker_coordenada.*');
$this->db->from('tracker_coordenada, tracker_veiculo');
$this->db->where('tracker_coordenada.veiculo_codigo = tracker_veiculo.veiculo_codigo');
$this->db->where('tracker_veiculo.cli_cod',$cliente);
if($filtro !=NULL){
$this->db->where('tracker_veiculo.descricao',$filtro);
}
$query = $this->db->get('',$num, $offset);
return $query->result();
//$sql = "SELECT tracker_coordenada.* FROM 'tracker_coordenada','tracker_veiculo' WHERE tracker_coordenada.veiculo_codigo = tracker_veiculo.veiculo_codigo AND tracker_veiculo.cli_cod = ".$cliente;
//$resultado = $this->db->query($sql);
//return $resultado->result_array();
}
function conta_coordenadas($cliente){
//$query = $this->db->query("SELECT COUNT(ID) AS total FROM coordenadas WHERE news_id = $news_id");
//$row = $query->row();
//echo $row->total;
$this->db->where('tracker_veiculo.cli_cod', $cliente);
$this->db->where('tracker_veiculo.veiculo_codigo', 'tracker_coordenada.veiculo_codigo');
$query = $this->db->count_all('tracker_coordenada');
return $query;
}
function get_trackers($cliente){
$this->db->select('*');
$this->db->from('tracker_veiculo');
$this->db->where('tracker_veiculo.cli_cod',$cliente);
$query = $this->db->get();
return $query->result();
}
}
Controller:
<?php
class TrackerCtrl extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('tracker/TrackerModel');
$this->load->model('FuncoesModel');
$this->load->library('table');
$this->load->language("label");
$this->load->helper('form');
}
function index(){
if ($this->FuncoesModel->VerificaPermissao("listar", "tracker") != "S"){
redirect('principal/principalctrl/acessonegado');
}
$dados['titulo'] = $this->lang->line('Tracker');
$cliente = $this->session->userdata("par_cli_codigo");
$dados['user_trackers_list'] = $this->TrackerModel->get_trackers($cliente);
$dados['dinamico'] = '/tracker/TrackerView';
$dados['filtro'] = $this->input->post('frota_list');
$this->load->vars($dados);
$this->load->view('/principal/PrincipalView');
}
function listar($dados=""){
$dados['titulo'] = $this->lang->line('Tracker');
$cliente = $this->session->userdata("par_cli_codigo");
$dados['filtro'] = $this->input->post('frota_list');
$dados['user_trackers_list'] = $this->TrackerModel->get_trackers($cliente);
$dados['dinamico'] = '/tracker/TrackerRelatorioView';
//Paginacao
$config['base_url'] = base_url().'index.php/tracker/trackerctrl/listar/';
$config['total_rows'] = $this->TrackerModel->conta_coordenadas($cliente);
$config['per_page'] = 5;
$config['uri_segment'] = 4;
$config['first_link'] = $this->lang->line('Primeiro');
$config['last_link'] = $this->lang->line('Último');
$config['next_link'] = $this->lang->line('Próximo');
$config['prev_link'] = $this->lang->line('Anterior');
$dados['get_coordenadas'] = $this->TrackerModel->get_coordenadas($cliente, $this->input->post('frota_list'), $config['per_page'],$this->uri->segment(4));
$this->pagination->initialize($config);
$dados["paginacao"] = $this->pagination->create_links();
$this->load->vars($dados);
$this->load->view('/principal/PrincipalView');
}
}
View:
<?
if($this->session->flashdata('msg')){
?>
<div style="background:#FF0000; text-align:center" align="center">
<font color="#FFFFFF"><?=$this->session->flashdata('msg')?></font>
</div>
<?
}
?>
<div class="row-fluid sortable">
<div class="box span12">
<div class="box-header" data-original-title>
<h2><i class="icon-eject"></i><span class="break"></span><?=$titulo?></h2>
<div class="box-icon">
<a href="#" class="btn-minimize"><i class="icon-chevron-up"></i></a>
</div>
</div>
<div class="box-content">
<div class="control-group">
<label class="control-label" for="typeahead"><font color="#FF0000"></font><?=$this->lang->line('Veículo')?>:</label>
<div class="controls">
<form id="form" name="form" method="post" action="<?=site_url('tracker/trackerctrl/listar/')?>">
<select name="frota_list" id="frota_list" style="width:300px" >
<? foreach($user_trackers_list as $opcao){?>
<option><?=$opcao->descricao?></option>
<? }?>
</select>
<br><br>
<button class="btn btn-small btn-primary" type="submit" id="btn_filtrar" name="btn_filtrar"><?=$this->lang->line('Filtrar')?></button>
<?=form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash());?>
</form>
</div>
</div>
</div><!--/span-->
</div><!--/row-->