Weird CakePHP (1.3) Pagination component behaviour -
have users list page result can modified using gender, city , country selects (dropdowns), , it's working fine. have lot of users need put pagination well, , here comes "weird" part (i sure it's not weird cannot figure out problem comes from): when select gender, pagination works great , can navigate between of pages, if select city instance (in addition or not of gender), pagination numbers right lost city restriction when move page.
tried understand happens filters displaying $this->data
. , says same before: working fine gender ($this->data['users']['gender']
go through pagination pages), other parameters got lost once try navigate away.
thing there isn't difference between filter gender
, other ones, either on controller side or in view (both select inputs).
on more technical side, here's bit of code:
//in 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 ?'] = 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');
can see, use paginate()
function within controller. still don't understand why it's working gender filter , not rest
cheers,
nicolas.
your problem not in controller, while in helper. when pass variable first time, it's working, because there posted variable, pagination doesn't handle these variables unless pass them pagination helper.
read this article , in opinion it's best pass gender, , city via _get.
Comments
Post a Comment