Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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?</p> <p>I suppose it would be possible to set your pagination config 'base_url' to this:</p> <pre><code>$this-&gt;load-&gt;helper('url'); $this-&gt;load-&gt;library('pagination'); $config['base_url'] = current_url().'?'.http_build_query($_POST); $config['total_rows'] = 200; $config['per_page'] = 20; $this-&gt;pagination-&gt;initialize($config); echo $this-&gt;pagination-&gt;create_links(); </code></pre> <p>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...</p> <p><strong>UPDATE:</strong></p> <p>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.:</p> <pre><code>&lt;input type="text" name="search[criteria1]" /&gt; &lt;input type="text" name="search[criteria2]" /&gt; &lt;input type="text" name="search[criteria3]" /&gt; </code></pre> <p>Then, in your controller:</p> <pre><code>... public function some_resource() { $this-&gt;load-&gt;model('Some_model'); $search_criteria = $this-&gt;input-&gt;get_post('search'); if ($search_criteria) { // make sure here to remove any unsupported criteria // (or in the model is usually a bit more modular, but // it depends on how strictly you follow MVC) $results = $this-&gt;Some_model-&gt;search($search_criteria); } else { // If no search criteria were given, return unfiltered results $results = $this-&gt;Some_model-&gt;get_all(); } $this-&gt;load-&gt;view('some_view', array( 'results' =&gt; $results, 'pagination_base' =&gt; current_url().'?'.http_build_query($search_criteria) )); } ... </code></pre> <p>Because I specified $this->input-><strong>get_post</strong>(), 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload