views:

50

answers:

1

Hi,
I have a users list page where the result can be modified by using gender, city and country selects (dropdowns), and it's working perfectly fine. As we have a lot of users I need to put a pagination as well, and here comes the "weird" part (I am sure it's not weird but I just cannot figure out where the problem comes from): when I select a gender, the pagination works great and I can navigate between all of the pages, but if I select a city for instance (in addition or not of the gender), the pagination numbers are right but I lost the city restriction when I move to another page.


So I tried to understand what happens to my filters by displaying the $this->data. And it says exactly the same as before: working perfectly fine with the gender ($this->data['users']['gender'] go through all the pagination pages), but the other parameters just got lost once I try to navigate away.
The thing is that there isn't any difference between the filter gender and the other ones, either on the controller side or in the view (both are select inputs).

On a more technical side, here's a bit of my code:

    //In the controller function
    if (!empty($this->data['users']['gender'])) {
        $conditions['gender'] = $this->data['users']['gender'];
    }
    if (!empty($this->data['users']['country_id'])) {
        $conditions['city_id'] = 
            $this->User->City->find(
                'list', 
                array(
                    'conditions' => array(
                        'country_id' => $this->data['users']['country_id']), 
                    'fields' => 'City.id'));
    }
    if (!empty($this->data['users']['city_id'])) {
        if($this->data['users']['city_id'] == 'NULL') {
            $conditions['city_id IS ?'] = NULL;
        } else {
            $conditions['city_id'] = $this->data['users']['city_id'];
        }
    }
    //debug($this->data);

    $options = array(
        'limit' => 20,
        'order' => 'User.lastname ASC',
        'conditions' => $conditions);
    $this->paginate = $options;
    $users = $this->paginate('User');


As you can see, I use the paginate() function within the controller. I still don't understand why it's working for the gender filter and not the rest


Cheers,
Nicolas.

+1  A: 

Your problem is not in the controller, while in the helper. When you pass the variable for the first time, it's working, because there is posted variable, but the pagination doesn't handle these variables unless you pass them to the pagination helper.

Read this article and in my opinion it's best to pass the gender, and city via _GET.

Nik
Hi, I read the entire article and after some times spent on make everything working, it's working like a charm with your _GET suggestion as well. Thanks.
Nicolas