mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Adding ability to inject an ajax provider class into paginator helper. updating tests.
This commit is contained in:
parent
27437a808d
commit
b1a27b1760
2 changed files with 25 additions and 3 deletions
|
@ -33,7 +33,7 @@ class PaginatorHelper extends AppHelper {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $helpers = array('Html', 'Ajax');
|
var $helpers = array('Html');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the default model for paged recordsets
|
* Holds the default model for paged recordsets
|
||||||
|
@ -42,6 +42,13 @@ class PaginatorHelper extends AppHelper {
|
||||||
*/
|
*/
|
||||||
var $__defaultModel = null;
|
var $__defaultModel = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class used for 'Ajax' pagination links.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
**/
|
||||||
|
var $_ajaxHelperClass = 'Js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the default options for pagination links
|
* Holds the default options for pagination links
|
||||||
*
|
*
|
||||||
|
@ -66,6 +73,21 @@ class PaginatorHelper extends AppHelper {
|
||||||
*/
|
*/
|
||||||
var $options = array();
|
var $options = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links.
|
||||||
|
*
|
||||||
|
* Use `var $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper
|
||||||
|
* or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
|
||||||
|
* adapter before including PaginatorHelper in your helpers array.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
**/
|
||||||
|
function __construct($config = array()) {
|
||||||
|
$ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js';
|
||||||
|
$this->helpers[] = $ajaxProvider;
|
||||||
|
$this->_ajaxHelperClass = $ajaxProvider;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current paging parameters from the resultset for the given model
|
* Gets the current paging parameters from the resultset for the given model
|
||||||
*
|
*
|
||||||
|
@ -271,7 +293,7 @@ class PaginatorHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
$url = $this->url($url, true, $model);
|
$url = $this->url($url, true, $model);
|
||||||
|
|
||||||
$obj = isset($options['update']) ? 'Ajax' : 'Html';
|
$obj = isset($options['update']) ? $this->_ajaxHelperClass : 'Html';
|
||||||
$url = array_merge(array('page' => $this->current($model)), $url);
|
$url = array_merge(array('page' => $this->current($model)), $url);
|
||||||
$url = array_merge(Set::filter($url, true), array_intersect_key($url, array('plugin'=>true)));
|
$url = array_merge(Set::filter($url, true), array_intersect_key($url, array('plugin'=>true)));
|
||||||
return $this->{$obj}->link($title, $url, $options);
|
return $this->{$obj}->link($title, $url, $options);
|
||||||
|
|
|
@ -42,7 +42,7 @@ class PaginatorHelperTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
$this->Paginator = new PaginatorHelper();
|
$this->Paginator = new PaginatorHelper(array('ajax' => 'Ajax'));
|
||||||
$this->Paginator->params['paging'] = array(
|
$this->Paginator->params['paging'] = array(
|
||||||
'Article' => array(
|
'Article' => array(
|
||||||
'current' => 9,
|
'current' => 9,
|
||||||
|
|
Loading…
Add table
Reference in a new issue