Skip to content

Commit

Permalink
Work on allowing custom view passed to paginator links method.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 29, 2013
1 parent efe3300 commit 9d1150c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/changes.json
Expand Up @@ -31,7 +31,8 @@
{"message": "Added App::middleware method to inject middlewares onto Stack.", "backport": null},
{"message": "Deprecate 'close' application hooks, Stack middlewares should be used instead.", "backport": null},
{"message": "A new packages directory within `lang` can now override package language files.", "backport": null},
{"message": "Added new 'Auth::viaRemember method to determine if user was authed via 'remember me' cookie.", "backport": null}
{"message": "Added new 'Auth::viaRemember method to determine if user was authed via 'remember me' cookie.", "backport": null},
{"message": "Allow passing a view name to paginator's 'links' method.", "backport": null}
],
"4.0.x": [
{"message": "Added implode method to query builder and Collection class.", "backport": null},
Expand Down
10 changes: 7 additions & 3 deletions src/Illuminate/Pagination/Environment.php
Expand Up @@ -109,13 +109,14 @@ public function make(array $items, $total, $perPage)
* Get the pagination view.
*
* @param \Illuminate\Pagination\Paginator $paginator
* @param string $view
* @return \Illuminate\View\View
*/
public function getPaginationView(Paginator $paginator)
public function getPaginationView(Paginator $paginator, $view = null)
{
$data = array('environment' => $this, 'paginator' => $paginator);

return $this->view->make($this->getViewName(), $data);
return $this->view->make($this->getViewName($view), $data);
}

/**
Expand Down Expand Up @@ -191,10 +192,13 @@ public function getPageName()
/**
* Get the name of the pagination view.
*
* @param string $view
* @return string
*/
public function getViewName()
public function getViewName($view = null)
{
if ( ! is_null($view)) return $view;

return $this->viewName ?: 'pagination::slider';
}

Expand Down
7 changes: 4 additions & 3 deletions src/Illuminate/Pagination/Paginator.php
Expand Up @@ -163,11 +163,12 @@ protected function isValidPageNumber($page)
/**
* Get the pagination links view.
*
* @param string $view
* @return \Illuminate\View\View
*/
public function links()
public function links($view = null)
{
return $this->env->getPaginationView($this);
return $this->env->getPaginationView($this, $view);
}

/**
Expand Down Expand Up @@ -440,7 +441,7 @@ public function offsetUnset($key)
public function toArray()
{
return array(
'total' => $this->total, 'per_page' => $this->perPage,
'total' => $this->total, 'per_page' => $this->perPage,
'current_page' => $this->currentPage, 'last_page' => $this->lastPage,
'from' => $this->from, 'to' => $this->to, 'data' => $this->getCollection()->toArray(),
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Pagination/PaginationPaginatorTest.php
Expand Up @@ -91,7 +91,7 @@ public function testPaginationContextHandlesPageMissing()
public function testGetLinksCallsEnvironmentProperly()
{
$p = new Paginator($env = m::mock('Illuminate\Pagination\Environment'), array('foo', 'bar', 'baz'), 3, 2);
$env->shouldReceive('getPaginationView')->once()->with($p)->andReturn('foo');
$env->shouldReceive('getPaginationView')->once()->with($p, null)->andReturn('foo');

$this->assertEquals('foo', $p->links());
}
Expand Down

0 comments on commit 9d1150c

Please sign in to comment.