Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use current request uri instead of a route uri #3

Open
wants to merge 1 commit into
base: 3.2/develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions classes/kohana/pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class Kohana_Pagination {

// Query offset
protected $offset;

// Request object
protected $_request;

// Route to use for URIs
protected $_route;

// Parameters to use with Route to create URIs
protected $_route_params = array();

Expand All @@ -83,21 +83,21 @@ public function __construct(array $config = array(), Request $request = NULL)
{
// Overwrite system defaults with application defaults
$this->config = $this->config_group() + $this->config;

// Assing Request
if ($request === NULL)
{
$request = Request::current();
}

$this->_request = $request;

// Assign default Route
$this->_route = $request->route();

// Assign default route params
$this->_route_params = $request->param();

// Pagination setup
$this->setup($config);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public function setup(array $config = array())
else
{
$query_key = $this->config['current_page']['key'];

switch ($this->config['current_page']['source'])
{
case 'query_string':
Expand Down Expand Up @@ -221,13 +221,13 @@ public function url($page = 1)
switch ($this->config['current_page']['source'])
{
case 'query_string':
return URL::site($this->_route->uri($this->_route_params).

return URL::site($this->_request->uri().
$this->query(array($this->config['current_page']['key'] => $page)));

case 'route':
return URL::site($this->_route->uri(array_merge($this->_route_params,

return URL::site($this->_route->uri(array_merge($this->_route_params,
array($this->config['current_page']['key'] => $page))).$this->query());
}

Expand Down Expand Up @@ -277,11 +277,11 @@ public function render($view = NULL)
// Pass on the whole Pagination object
return $view->set(get_object_vars($this))->set('page', $this)->render();
}


/**
* Request setter / getter
*
*
* @param Request
* @return Request If used as getter
* @return $this Chainable as setter
Expand All @@ -290,15 +290,15 @@ public function request(Request $request = NULL)
{
if ($request === NULL)
return $this->_request;

$this->_request = $request;

return $this;
}

/**
* Route setter / getter
*
*
* @param Route
* @return Route Route if used as getter
* @return $this Chainable as setter
Expand All @@ -307,15 +307,15 @@ public function route(Route $route = NULL)
{
if ($route === NULL)
return $this->_route;

$this->_route = $route;

return $this;
}

/**
* Route parameters setter / getter
*
*
* @param array Route parameters to set
* @return array Route parameters if used as getter
* @return $this Chainable as setter
Expand All @@ -324,15 +324,15 @@ public function route_params(array $route_params = NULL)
{
if ($route_params === NULL)
return $this->_route_params;

$this->_route_params = $route_params;

return $this;
}

/**
* URL::query() replacement for Pagination use only
*
*
* @param array Parameters to override
* @return string
*/
Expand All @@ -348,16 +348,16 @@ public function query(array $params = NULL)
// Merge the current and new parameters
$params = array_merge($this->_request->query(), $params);
}

if (empty($params))
{
// No query parameters
return '';
}

// Note: http_build_query returns an empty string for a params array with only NULL values
$query = http_build_query($params, '', '&');

// Don't prepend '?' to an empty string
return ($query === '') ? '' : ('?'.$query);
}
Expand Down