mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Fixes for Paginator / setCurrentPage
remember() now works
This commit is contained in:
parent
f4e60f105a
commit
0fc489c7cb
16
UPGRADE.md
16
UPGRADE.md
@ -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()
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user