Monday, April 29, 2013

Re: Paginate search results

It looks like you are making a call to the PaginatorHelper in the view, when no actual pagination has taken place. And this happens when you submit the search form.

Firstly, I would recommend not using a POST for your search form.  Use a GET instead, so that everything is on the query string, and you don't need to rely on Sessions.

I would also recommend setting up the paginator to use the query string, rather than named params, and you see why in the second.

In your search form create, specify the url option to be $this->Paginator->url().  This make sure that when you post the search, via a GET, extra settings like the sort field and direction, what page you are on, and the limit are remembered.

Also, when you specifiy $this->Paginator->sort(), also pass through $this->Paginator->url(), so that your search field is remembered when you change the sort.  You may also need to do a similar thing for $this->Paginator->numbers(), first(), prev(), last() and next() (which reminds me, I better check the code I was working on today, doing just this very thing).

By using $this->Paginator->url(), you can pass around the paginator parameters, and any extra params (like search filters), and by using GET in your form, each request is stateless, and doesn't require a session.

On Sunday, 28 April 2013 04:17:43 UTC+10, Lilit Bakunts wrote:
Hi people.
I'm new to cakephp and need your help. I have this search function in my
UsersController, so there's a problem with search result pagination. The
first page shows first five names properly, but next pages does not show
anything. I need that this session save all my users, then check and
basically read it in next pages.
so how it should be?
th error message

*Undefined index: pageCount [CORE\Cake\View\Helper\PaginatorHelper.php, line
702]*

and the
public function search() {

                if (!empty($this -> data)) {
                        $keyword = $this -> data['User']['search'];
                        $this -> Session -> write('users', $keyword);
                        
                        if ($this -> Session -> check('users')) {
                                $keyword = $this -> Session -> read('users');

                        } elseif (isset($keyword, $this -> data['User']['search'])) {
                                $this -> paginate = array('conditions' => array('OR' =>
array("User.first_name LIKE" => "$keyword%", "User.last_name LIKE" =>
"$keyword%")), 'limit' => 5);
                                $this -> set('users', $this -> paginate('User'));

                        }
                }

pls helpp
Thanks in advance :)



--
View this message in context: http://cakephp.1045679.n5.nabble.com/Paginate-search-results-tp5714685.html
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: