Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.1

Bug #12837 If $_SESSION['setPerPage'] be set, Pager always uses it
Submitted: 2008-01-06 13:26 UTC
From: parham Assigned: quipo
Status: Closed Package: Pager (version 2.4.4)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2008-01-06 13:26 UTC] parham (Hady Ahmady Phoulady)
Description: ------------ If $_SESSION['setPerPage'] be set, Pager always uses it whether you had set the 'useSessions' parameter in options or not (while it should use 'perPage' parameter in options if it had been set). It can be fixed by changing the line #1453 in Common.php to if (!empty($_SESSION[$this->_sessionVar]) && $this->_useSessions) { in version 2.4.4 but maybe there's a better way? (the old line was "if (!empty($_SESSION[$this->_sessionVar])) {") Also when I create another Pager and set 'perPage' parameter in options and also 'useSessions' parameter to true, it doesn't work (neither after changing the line above). It's more expected that it sets the new 'perPage' to session rather than using the old data in sessions. I couldn't find anywhere that what was the actual intention of Pager (whether to use what has been set in 'perPage' parameter in options or not when 'useSession' parameter had been set to true) so I added this: if (!empty($options['perPage']) && $this->_useSessions) { $_SESSION[$this->_sessionVar] = $this->_perPage; } right after line #1445 (after the it starts the session). Anyways, the script below demonstrate the bug. Test script: --------------- $data = array(); for ($i = 0; $i < 100; $i++) $data[] = $i; $first_params = array( 'itemData' => $data, 'perPage' => 10, 'useSessions' => true, 'closeSession' => true, ); $first_pager = & Pager::factory($first_params); print_r($first_pager->getPageData()); $second_params = array( 'itemData' => $data, 'perPage' => 20, 'useSessions' => false, 'closeSession' => false ); $second_pager = & Pager::factory($second_params); print_r($second_pager->getPageData()); Expected result: ---------------- I expect that to see these lines in source of output: Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 ) Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 ) Actual result: -------------- But I see: Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 ) Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 )

Comments

 [2008-01-06 14:15 UTC] quipo (Lorenzo Alberton)
I've committed to CVS the "&& $this->_useSessions" suggested check, thanks. If you have multiple Pager instances, you can set a different 'sessionVar' option name for each one so they won't interfere. > It's more expected that it sets the new > 'perPage' to session rather than using > the old data in sessions. actually the intended behaviour is the opposite: 'perPage' is used as the default value when the session hasn't been set yet. Then, the session value has higher priority.
 [2008-01-08 09:04 UTC] parham (Hady Ahmady Phoulady)
OK, I see. Thanks for the explanation.