Skip to content

Commit

Permalink
Adding ability to inject an ajax provider class into paginator helper…
Browse files Browse the repository at this point in the history
…. updating tests.
  • Loading branch information
markstory committed Aug 9, 2009
1 parent 6ca2127 commit 18be141
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions cake/libs/view/helpers/paginator.php
Expand Up @@ -33,7 +33,7 @@ class PaginatorHelper extends AppHelper {
*
* @var array
*/
var $helpers = array('Html', 'Ajax');
var $helpers = array('Html');

/**
* Holds the default model for paged recordsets
Expand All @@ -42,6 +42,13 @@ class PaginatorHelper extends AppHelper {
*/
var $__defaultModel = null;

/**
* The class used for 'Ajax' pagination links.
*
* @var string
**/
var $_ajaxHelperClass = 'Js';

/**
* Holds the default options for pagination links
*
Expand All @@ -66,6 +73,21 @@ class PaginatorHelper extends AppHelper {
*/
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
*
Expand Down Expand Up @@ -271,7 +293,7 @@ function link($title, $url = array(), $options = array()) {
}
$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(Set::filter($url, true), array_intersect_key($url, array('plugin'=>true)));
return $this->{$obj}->link($title, $url, $options);
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/view/helpers/paginator.test.php
Expand Up @@ -42,7 +42,7 @@ class PaginatorHelperTest extends CakeTestCase {
* @return void
*/
function setUp() {
$this->Paginator = new PaginatorHelper();
$this->Paginator = new PaginatorHelper(array('ajax' => 'Ajax'));
$this->Paginator->params['paging'] = array(
'Article' => array(
'current' => 9,
Expand Down

0 comments on commit 18be141

Please sign in to comment.