PaginationRecall for CakePHP 2.x

by Zaphod
Have you used PaginationRecall component with CakePHP 1.x and wonder why it doesn't work with CakePHP 2.x? Searching for a way to keep the page or ordering of pagination?
I changed the old PaginationRecall component of mattc so that it works under CakePHP 2.x. Here's the changes code:



<?php
/*
 * Pagination Recall CakePHP Component
 * Copyright (c) 2008 Matt Curry
 * www.PseudoCoder.com
 *
 * @author      mattc <matt@pseudocoder.com>
 * @version     2.0
 * @license     MIT
 * Changed to cakephp 2.x by 
 *
 */

class PaginationRecallComponent extends Component {
    var 
$components = array('Session');
    var 
$Controller null;

    function 
initialize(&$controller) {
        
$this->Controller = & $controller;

        
$options array_merge($this->Controller->request->params,
                                    
$this->Controller->params['url'],
                                    
$this->Controller->passedArgs
                                  
);
        
$vars = array('page''sort''direction''filter');
        
$keys array_keys($options);
        
$count count($keys);

        for (
$i 0$i $count$i++) {
            if (!
in_array($keys[$i], $vars) || !is_string($keys[$i])) {
              unset(
$options[$keys[$i]]);
            }
        }
    
        
//save the options into the session
        
if ($options) {
            if (
$this->Session->check("Pagination.{$this->Controller->modelClass}.options")) {
                
$options array_merge($this->Session->read("Pagination.{$this->Controller->modelClass}.options"), $options);
            }
      
            
$this->Session->write("Pagination.{$this->Controller->modelClass}.options"$options);
        }

        
//recall previous options
        
if ($this->Session->check("Pagination.{$this->Controller->modelClass}.options")) {
            
$options $this->Session->read("Pagination.{$this->Controller->modelClass}.options");
            
$this->Controller->passedArgs array_merge($this->Controller->passedArgs$options);
            
$this->Controller->request->params['named'] = $options;
        }
    }
}
?>

Report

More on Articles

Advertising

Comments

  • Dvd74 posted on 11/25/13 03:29:50 PM
    I think there is a bug.
    Because the paginator not come back to the first page.
login to post a comment.