Adding ability to inject an ajax provider class into paginator helper. updating tests.

This commit is contained in:
mark_story 2009-08-09 17:32:29 -04:00
parent 6ca2127aea
commit 18be1418cd
2 changed files with 25 additions and 3 deletions

View file

@ -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 @@ class PaginatorHelper extends AppHelper {
}
$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);

View file

@ -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,