Note that there are some explanatory texts on larger screens.

plurals
  1. POpagination with search results in cakephp
    primarykey
    data
    text
    <p>I've implemented a user model and I have a simple search form for searching by gender, age, location. I'm using the paginator to paginate the results. The problem is that it's only remembering the search criteria on the first page. When I click on page 2, or next etc.. It defaults back to searching all users. </p> <p>Here's my dirty search code in my controller, basically it just checks the submitted form fields and does a query on the matching field in the Users table and then paginates the results: </p> <pre><code>if (!empty($this-&gt;data)) { // by name if (!empty($this-&gt;data['User']['search_name'])) { $this-&gt;paginate = array('conditions' =&gt; array('visible'=&gt;1, 'OR'=&gt;array( 'User.username LIKE' =&gt; '%'.$this-&gt;data['User']['search_name'].'%', 'User.firstname LIKE' =&gt; '%'.$this-&gt;data['User']['search_name'], 'User.lastname LIKE' =&gt; '%'.$this-&gt;data['User']['search_name']) ), 'limit'=&gt;'10', 'order'=&gt;'User.username'); } // by gender else if (!empty($this-&gt;data['User']['search_gender'])) { $this-&gt;paginate = array('conditions' =&gt; array( 'visible'=&gt;1, 'User.gender' =&gt; $this-&gt;data['User']['search_gender'] ), 'limit'=&gt;'10', 'order'=&gt;'User.username'); } // by state else if (!empty($this-&gt;data['User']['search_state'])) { $this-&gt;paginate = array('conditions' =&gt; array( 'visible'=&gt;1, 'User.state' =&gt; $this-&gt;data['User']['search_state'] ), 'limit'=&gt;'10', 'order'=&gt;'User.username'); } // Send the results for the above criteria to the view $results = $this-&gt;paginate('User'); $this-&gt;set('users', $results); } // Default retrieval of all users else { $this-&gt;paginate = array('conditions'=&gt;array('visible'=&gt;1), 'limit'=&gt;'10', 'order'=&gt;'User.username'); $this-&gt;set('users', $this-&gt;paginate('User')); } </code></pre> <p>I'm trying to figure out how to make subsequent pages of the pagination remember my search criteria. Thanks for any help.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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