Hello guys,
I need help for admin side:
In 'one module' I have link -> fuel_url('another_module', array('id' => $id)), which produces URI -> '/admin/another_module?id=1', and on click at that link site goes to the 'another_module' page.
I need to develop auto filtration for items on 'another_module' page by GET parameters, in my example it is by $_GET['id].
I have extended list_items() method in the another_model.php file, but I can't get parameters from URI in it (((.
I have tried CI method $param_id = $this->input->get('id'), and on die($param_id); I can see it.
But when I add it to the WHERE condition, list_items() doesn't see it.
I do it like this:
----------
public function list_items($limit = NULL, $offset = NULL, $col = 'id', $order = 'asc', $just_count = FALSE)
{
$param_id = $this->input->get('id')
$this->db->where(array('id' => $param_id)) ;
$data = parent::list_items($limit, $offset, $col, $order, $just_count);
return $data;
}
----------
I suppose it happens because of AJAX request to - "
http://domain/admin/another_module/items/?search_term=&limit=50&view_type=list&offset=0&order=asc&col=name&fuel_inline=0".
Please help me. How can I get GET parameters in the _model files?
Thank you.
Comments
So using something like :
/* I couldn't read chantiers_id from get method so I used last_url function to retrieve data what we sent with get method */ $last_url = last_url(); $params = explode( '?param =', $last_url); $count_array = count( $param ); if ( $count_array == 1) { $params = null; } elseif ( $count_array == 2 ) { $param = explode( '&', $params [1]); $param = $param [0]; };
$param is that variable what I need to send and get. Also you may need how I sending, so I used simple:
<li><a href="<?=fuel_url('another_module?param='.$id.'¶m2=active', TRUE)?>" class="ico ico_view"><?=lang('btn_another_module')?></a></li>
This is not the best way, but working if there any others solutions ?
In your fuel/application/config/MY_fuel_modules.php file, add the following filtering parameters to your modules configuration:
$config['modules']['another_module'] = array( ... 'filters' => array( 'id' => array('type' => 'hidden'), 'other_param' => array('type' => 'select', 'options' => array('option1' => 'option1')), // additional example ... );
This will create additional form fields in the list view that will get passed as $_GET parameters when rendering the list view. In this case, one will be a hidden field ("id") and the other will be a select list).
I have added filters in the config/MY_fuel_modules.php file, and now I see hidden field in the list, and I see it in the AJAX request.
But I still can't set value from Get ((.
I'm trying to do this in another_module_model.php->list_items():
public function list_items($limit = NULL, $offset = NULL, $col = 'id', $order = 'asc', $just_count = FALSE)
{
$param_id = $this->input->get('id');
parent::form_fields(array('id' => $param_id));
$data = parent::list_items($limit, $offset, $col, $order, $just_count);
return $data;
}
Please help me to resolve this.
global $_GET;
echo $_GET['id'];
i think all those $this->input->get('id') are just functions masked the fundamental php function. so the old way of writing php should be working...as long as the function is called.
My question is: how to set filter value in the _model.php file?
The problem is because FUEL does an AJAX page reload after loading page by passed link. At first I see passed GET value, but after "AJAX page reload" thing I can't see required GET parameter, because I didn't set it on that AJAX request.
That AJAX request automatically gathers filters values, so I need simply put my value into filter field before page does AJAX reload.
I'm trying to do it in the _model->list_items() method, but FUEL documentation is poor and hard to understand for me (.