using get variables in CMS?

edited March 2013 in Modules
In the CMS list view, I'd like to display either only records that have been exported or all records the default being records that have not been exported. There's a column in the db table named `exported` which will either be 0 or 1. I have the following in the list view of /application/models/players_model.php:
function list_items($limit = NULL, $offset = NULL, $col = 'last_name', $order = 'asc') { $CI =& get_instance(); $user = $CI->fuel_auth->user_data(); if ( $user['super_admin'] == 'no' ) { $this->load->model('clients_model'); $this->load->model('players_to_clients_model'); $client = $this->clients_model->find_one_by_fuel_user_id($user['id']); $client_id = $client['id']; $this->db->select("DISTINCT players.id, players.first_name, players.last_name, players.email, players.status, players.power_play_balance, players_to_clients.client_id as promoter_id", FALSE); $this->db->from("players_to_clients,clients"); if( !isset($_GET['exported']) ) { $where = array('clients.id' => (int)($client_id), 'players_to_clients.client_id' => (int)($client_id), 'players_to_clients.player_id' => 'players.id', 'exported' => 0); } else { //echo $_GET['exported']; $where = array('clients.id' => (int)($client_id), 'players_to_clients.client_id' => (int)($client_id), 'players_to_clients.player_id' => 'players.id'); } $this->db->where($where, NULL, FALSE); } else { $this->db->select('DISTINCT players.id, players.first_name, players.last_name, players.email, players.status, players.power_play_balance', FALSE); } $data = parent::list_items($limit, $offset, $col, $order); return $data; }
So, for example, the`exported` value is set to 1 for all the `players` records. (They've been exported.) Whether or not I add the 'exported' querystring variable like:
/fuel/players?exported=all
or leave it off like this:
/fuel/players

the resulting recordset seems to come from using the first $where array so the above returns an empty set.
But, if I flip the if statement from !isset to isset like:

if( isset($_GET['exported']) ) { //echo $_GET['exported']; $where = array('clients.id' => (int)($client_id), 'players_to_clients.client_id' => (int)($client_id), 'players_to_clients.player_id' => 'players.id'); } else { echo $_GET['exported']; $where = array('clients.id' => (int)($client_id), 'players_to_clients.client_id' => (int)($client_id), 'players_to_clients.player_id' => 'players.id', 'exported' => 0); }
the resulting recordset is always all records no mater whether or not I include the GET var in the querystring. So it still seems to be using the first $where array.

If I echo out $_GET['exported'] on the proper side of the statement it only echos when the GET var is present (which is what it should do of course) but the result still only uses the first $where array.

Any ideas?

One thing I have noticed is that the page seems to load twice in rapid succession. I might be imagining things though.

Comments

  • edited 5:08PM
    UPDATE:

    I just changed the above if statement to be:

    if( !isset($_GET['exported']) ) { echo "NOT SET"; $where = array('clients.id' => (int)($client_id), 'players_to_clients.client_id' => (int)($client_id), 'players_to_clients.player_id' => 'players.id', 'exported' => 0); } else { echo "ISSET: " . $_GET['exported']; $where = array('clients.id' => (int)($client_id), 'players_to_clients.client_id' => (int)($client_id), 'players_to_clients.player_id' => 'players.id'); }
    and it's not running the 'else' side of the statement. I've ben staring at this for so long I bet there's something right under my nose that I can't see. Help!!
  • edited 5:08PM
    Ok, Now I'm realizing that maybe I can't access $_GET vars in the CMS even though I have the following set in application/config/config.php

    $config['allow_get_array'] = TRUE;
    $config['enable_query_strings'] = FALSE;
  • edited 5:08PM
    So, maybe there's a better way to accomplish the filtering. I want to give fuel users the ability to hide records that have already been exported or to show them and make them available to be exported again. Is there a way to do this without using GET vars?
Sign In or Register to comment.