I have a few internal sites that help me manage data. CakePHP's paginate() function is wonderful when it comes to getting functional tables with content quickly.
The thing about watching paginated data is that I use it in a certain context - for example right now I'm looking at all my recipes sorted by creation date, because I want to edit some of those that I added in the second half of last year. The problem is that whenever I click on something other than links generated by this paginator (for example I edit one of the recipes) and then go back to the list, I have to set sorting again.
Here's a short code that makes Cake remember in session how were my recipes sorted last time:
if(isset($this->params['named']['sort'])) { // user clicked on a "sort by" link, write his choice to the session
$this->Session->write('recipes_sort',array($this->params['named']['sort']=>$this->params['named']['direction']));
}
elseif($this->Session->check('recipes_sort')) { // user has "saved" his sorting preference before
$this->paginate['order'] = $this->Session->read('recipes_sort');
}
Drop it in your controller's action (for example recipes/index) before you call $this->paginate();.
Recent comments
2 years 9 weeks ago
2 years 11 weeks ago
2 years 21 weeks ago
2 years 38 weeks ago
3 years 29 weeks ago
3 years 37 weeks ago
4 years 14 weeks ago
4 years 15 weeks ago
4 years 27 weeks ago
4 years 30 weeks ago