I am new with codeigniter. Hope can help to solve problem on codeigniter pagination.
- i have selected some records from my view and pass to my controller using $_POST.
- the controller will use $_POST variable to select records from a model.
- then records will be display in the same view with pagination.
step 1-3 is okey, the view display correct info.
- when press on the pagination button from my view. This will call the same controller but $_POST info be come blank. So, my view is not displaying with the selected records as needed.
hope can help out.
i have simplied the code as follows:-
controllers:
$config['total_rows']=$this->invdata_model->getFilterData_numRows();
$config['base_url']=site_url('site/users_area') ;
$config['uri_segment'] = '3';
$config['per_page']=18;
$config['num_links']=4;
$this->pagination->initialize($config);
$data['records']=$this->invdata_model->getFilterData_Rows($config['per_page'],$this->uri->segment(3));
$data['rec_country']=$this->invdata_model->country();
$this->load->view('includes/header');
$this->load->view('users_area_view',$data);
$this->load->view('includes/footer');
models:
$country = $this->input->post('country') ;
$this->db->select('stockno, bdlno, country,volton');
if (isset($country)) { $this->db->where_in('country',$country); }
$q=$this->db->get('inventory')->num_rows();
return $q ;
View
<?php echo form_open('site/users_area');
echo $this->table->generate($records);
echo $this->pagination->create_links() ; ?>
<div class="gadget">
<?php echo form_submit('submit','Apply','class="button_form"'); ?>
</div>
$gadget['gadget_name']='country';
$gadget['gadget_rec']=$rec_country;
$this->load->view('gadget',$gadget);
</form>
View Gadget
<div class="gadget">
<?php
$gadget_name2=$gadget_name.'[]';
echo "<ul>";
foreach ($gadget_rec as $item) {
echo '<li >';
echo '<div id="sectionname">'.$item.'</div>';
echo '<div id="sectioninput"><input type="checkbox" name="'.$gadget_name2.'" value="'.$item.'"></div>' ;
echo '-';
echo "</li>";
}
echo "<ul>";
?>
</div>
Thank you.
It sounds like an approach issue. Why are you using POST data to filter your data? The pagination library builds a query string to determine the offset of your database query results. Why can’t you use $_GET instead of $_POST?
I suppose it would be possible to set your pagination config ‘base_url’ to this:
And then in your controller, use $this->input->get_post(), rather than $this->input->post(). Be careful here–it’s rarely safe to pass the full post data directly into a model for processing. It would be better to use CI’s input class to prevent XSS attacks…
UPDATE:
To use CI’s input class, rather than $_POST or $_GET directly, I usually keep my form data in a “namespace” of sorts, i.e.:
Then, in your controller:
Because I specified $this->input->get_post(), it will first check for a query string parameter; if it doesn’t exist, it falls back to post data. This will allow you to use POST in your form, but still pass in the same data through the query string with the pagination class. However, really the form should be using the GET method, as you’re sending these parameters as a query, and not to send something to the server. Just my $.02 on that detail.