mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix notice errors in pagination link generation.
No errors should be emitted when creating links for models that were not paginated. Refs #6090
This commit is contained in:
parent
c3e1ba1dc9
commit
6df7bf9c21
2 changed files with 50 additions and 2 deletions
|
@ -1260,6 +1260,14 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
'paramType' => 'named'
|
||||
)
|
||||
);
|
||||
$result = $this->Paginator->sort('title', 'Title', array('model' => 'Client'));
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/sort:title/direction:asc'),
|
||||
'Title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->next('Next', array('model' => 'Client'));
|
||||
$expected = array(
|
||||
'span' => array('class' => 'next'),
|
||||
|
@ -1277,6 +1285,39 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating paging links for missing models.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPagingLinksMissingModel() {
|
||||
$result = $this->Paginator->sort('title', 'Title', array('model' => 'Missing'));
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/sort:title/direction:asc'),
|
||||
'Title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->next('Next', array('model' => 'Missing'));
|
||||
$expected = array(
|
||||
'span' => array('class' => 'next'),
|
||||
'a' => array('href' => '/index/page:2', 'rel' => 'next'),
|
||||
'Next',
|
||||
'/a',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('Prev', array('model' => 'Missing'));
|
||||
$expected = array(
|
||||
'span' => array('class' => 'prev'),
|
||||
'Prev',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testGenericLinks method
|
||||
*
|
||||
|
|
|
@ -120,7 +120,7 @@ class PaginatorHelper extends AppHelper {
|
|||
* Gets the current paging parameters from the resultset for the given model
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return array|null The array of paging parameters for the paginated resultset.
|
||||
* @return array The array of paging parameters for the paginated resultset.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::params
|
||||
*/
|
||||
public function params($model = null) {
|
||||
|
@ -128,7 +128,14 @@ class PaginatorHelper extends AppHelper {
|
|||
$model = $this->defaultModel();
|
||||
}
|
||||
if (!isset($this->request->params['paging']) || empty($this->request->params['paging'][$model])) {
|
||||
return null;
|
||||
return array(
|
||||
'prevPage' => false,
|
||||
'nextPage' => true,
|
||||
'paramType' => 'named',
|
||||
'pageCount' => 1,
|
||||
'options' => array(),
|
||||
'page' => 1
|
||||
);
|
||||
}
|
||||
return $this->request->params['paging'][$model];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue