开发者

Weird CakePHP (1.3) Pagination component behaviour

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);开发者_如何学JAVA
    $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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜