Permalink
Browse files

Work on allowing custom view passed to paginator links method.

  • Loading branch information...
taylorotwell committed Oct 29, 2013
1 parent efe3300 commit 9d1150c8851d22cb1a14faa35304b3dc7f17c94b
@@ -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},
@@ -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);
}
/**
@@ -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';
}
@@ -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);
}
/**
@@ -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(),
);
@@ -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());
}

0 comments on commit 9d1150c

Please sign in to comment.