Fixes for Paginator / setCurrentPage

remember() now works
This commit is contained in:
Samuel Georges 2015-02-07 10:24:28 +11:00
parent f4e60f105a
commit 0fc489c7cb
3 changed files with 25 additions and 13 deletions

View File

@ -31,11 +31,23 @@ Optional things you can delete, if they do not contain anything custom.
### Breaking code changes
**Model->remember() has been removed**
**App::make('paginator')->setCurrentPage(5);** should no longer be used
#### Paginator / setCurrentPage
**App::make('paginator')->setCurrentPage(5);** should no longer be used, instead pass as the second argument with the `paginate()` method `$model->paginate(25, 5);`
Old code:
App::make('paginator')->setCurrentPage($page);
$model->paginate($perPage);
New code:
$model->paginate($perPage, $page);
##### Paginator API changes
The following methods have changed:
getTotal() -> total()
getCurrentPage() -> currentPage()
getLastPage() -> lastPage()

View File

@ -1,6 +1,5 @@
<?php namespace Backend\Behaviors;
use Cache;
use System\Behaviors\SettingsModel;
use Backend\Models\UserPreferences;
@ -63,13 +62,9 @@ class UserPreferencesModel extends SettingsModel
public function getSettingsRecord()
{
$item = UserPreferences::forUser();
$record = Cache::remember($this->getCacheKey(), 1440, function() use ($item) {
return $item->scopeFindRecord(
$this->model,
$this->recordCode,
$item->userContext
)->first();
});
$record = $item->scopeFindRecord($this->model, $this->recordCode, $item->userContext)
->remember(1440, $this->getCacheKey())
->first();
return $record ?: null;
}

View File

@ -70,6 +70,11 @@ class Lists extends WidgetBase
*/
public $recordsPerPage;
/**
* @var int Current page number.
*/
protected $currentPageNumber;
/**
* @var string Message to display when there are no records in the list.
*/
@ -230,7 +235,7 @@ class Lists extends WidgetBase
*/
public function onPaginate()
{
App::make('paginator')->setCurrentPage(post('page'));
$this->currentPageNumber = post('page');
return $this->onRefresh();
}
@ -456,7 +461,7 @@ class Lists extends WidgetBase
else {
$model = $this->prepareModel();
$records = ($this->showPagination)
? $model->paginate($this->recordsPerPage)
? $model->paginate($this->recordsPerPage, $this->currentPageNumber)
: $model->get();
}
@ -959,7 +964,7 @@ class Lists extends WidgetBase
/*
* Persist the page number
*/
App::make('paginator')->setCurrentPage(post('page'));
$this->currentPageNumber = post('page');
return $this->onRefresh();
}