Skip to content

Commit

Permalink
No 'p' pageParam
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 19, 2015
1 parent 2f8a5e1 commit 708ed5a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ The max number of elements that should be included in each page, if pagination i
The query string param name that should be used to identify which page is being requested. By default this is set to `'page'`.

```php
'pageParam' => 'p',
'pageParam' => 'pg',
```

Note that it cannot be set to `'p'` because that’s the parameter Craft uses to check the requested path.


### Dynamic URL Patterns and Endpoint Configurations

Expand Down Expand Up @@ -162,7 +164,7 @@ return [
'defaults' => [
'elementType' => 'Entry',
'elementsPerPage' => 10,
'pageParam' => 'p',
'pageParam' => 'pg',
'transformer' => function(EntryModel $entry) {
return [
'title' => $entry->title,
Expand Down
2 changes: 1 addition & 1 deletion elementapi/ElementApi_PaginatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function _getCurrentPage()
{
$currentPage = $this->totalPages > 0 ? $this->totalPages : 1;
}
else if ($currentPage < 0)
else if (!is_numeric($currentPage) || $currentPage < 0)
{
$currentPage = 1;
}
Expand Down
5 changes: 5 additions & 0 deletions elementapi/controllers/ElementApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function actionGetElements($configFactory = null, array $config = null)
$config
);

if ($config['pageParam'] == 'p')
{
throw new Exception('The pageParam setting cannot be set to "p" because that’s the parameter Craft uses to check the requested path.');
}

if (!isset($config['elementType']))
{
throw new Exception('Element API configs must specify the elementType.');
Expand Down

0 comments on commit 708ed5a

Please sign in to comment.