Permalink
Browse files

Adding ability to inject an ajax provider class into paginator helper…

…. updating tests.
  • Loading branch information...
1 parent 27437a8 commit b1a27b1760e3972a67dbe153c040f1eec663266d @markstory markstory committed Aug 9, 2009
Showing with 25 additions and 3 deletions.
  1. +24 −2 cake/libs/view/helpers/paginator.php
  2. +1 −1 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -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
@@ -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
*
@@ -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
*
@@ -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);
@@ -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,

0 comments on commit b1a27b1

Please sign in to comment.