mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding additional Dispatcher fixes for named arguments; fixing parameters passed in Paginator URLs
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4232 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
3758445e8a
commit
9ce0247acc
4 changed files with 50 additions and 14 deletions
|
@ -215,9 +215,8 @@ class Dispatcher extends Object {
|
|||
if (!empty($controller->params['pass'])) {
|
||||
$controller->passed_args =& $controller->params['pass'];
|
||||
$controller->passedArgs =& $controller->params['pass'];
|
||||
$named = false;
|
||||
|
||||
if (is_array($controller->namedArgs) ) {
|
||||
if (is_array($controller->namedArgs)) {
|
||||
if(array_key_exists($params['action'], $controller->namedArgs)) {
|
||||
$args = $controller->namedArgs[$params['action']];
|
||||
} else {
|
||||
|
@ -234,19 +233,20 @@ class Dispatcher extends Object {
|
|||
unset($params['pass'][$argKey], $params['pass'][$argVal]);
|
||||
}
|
||||
} else {
|
||||
$named = true;
|
||||
$controller->passedArgs[$arg] = $value;
|
||||
$controller->namedArgs[$arg] = $value;
|
||||
}
|
||||
}
|
||||
} else if($controller->namedArgs === true) {
|
||||
$controller->namedArgs = array();
|
||||
}
|
||||
if($controller->namedArgs === true || $named == true) {
|
||||
|
||||
if (is_array($controller->namedArgs)) {
|
||||
$c = count($controller->passedArgs);
|
||||
for ($i = $c - 1; $i > -1; $i--) {
|
||||
if (isset($controller->passedArgs[$i]) && strpos($controller->passedArgs[$i], $controller->argSeparator) !== false) {
|
||||
list($argKey, $argVal) = explode($controller->argSeparator, $controller->passedArgs[$i]);
|
||||
$controller->passedArgs[$argKey] = $argVal;
|
||||
$controller->namedArgs = array();
|
||||
$controller->namedArgs[$argKey] = $argVal;
|
||||
unset($controller->passedArgs[$i]);
|
||||
unset($params['pass'][$i]);
|
||||
|
@ -256,7 +256,7 @@ class Dispatcher extends Object {
|
|||
} else {
|
||||
$controller->passed_args = null;
|
||||
$controller->passedArgs = null;
|
||||
if (is_array($controller->namedArgs) ) {
|
||||
if (is_array($controller->namedArgs)) {
|
||||
if(array_key_exists($params['action'], $controller->namedArgs)) {
|
||||
$args = $controller->namedArgs[$params['action']];
|
||||
} else {
|
||||
|
@ -271,8 +271,6 @@ class Dispatcher extends Object {
|
|||
|
||||
if (!empty($params['bare'])) {
|
||||
$controller->autoLayout = !$params['bare'];
|
||||
} else {
|
||||
$controller->autoLayout = $controller->autoLayout;
|
||||
}
|
||||
|
||||
$controller->webservices = $params['webservices'];
|
||||
|
|
|
@ -789,7 +789,7 @@ class Controller extends Object {
|
|||
function postConditions($data = array(), $op = null, $bool = 'AND', $exclusive = false) {
|
||||
if ((!is_array($data) || empty($data)) && empty($this->data)) {
|
||||
return null;
|
||||
} elseif ((!is_array($data) || empty($data)) && !empty($this->data)) {
|
||||
} elseif (!empty($this->data)) {
|
||||
$data = $this->data;
|
||||
}
|
||||
|
||||
|
@ -1000,12 +1000,13 @@ class Controller extends Object {
|
|||
|
||||
$count = $object->findCount($conditions);
|
||||
$paging = array(
|
||||
'page' => $page,
|
||||
'current' => count($results),
|
||||
'count' => $count,
|
||||
'prevPage' => ($page > 1),
|
||||
'nextPage' => ($count > ($page * $limit)),
|
||||
'pageCount' => ceil($count / $limit),
|
||||
'defaults' => $defaults,
|
||||
'defaults' => am(array('limit' => 20, 'step' => 1), $defaults),
|
||||
'options' => $options
|
||||
);
|
||||
$this->params['paging'][$object->name] = $paging;
|
||||
|
|
|
@ -212,6 +212,30 @@ class Set extends Object {
|
|||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Computes the difference between a Set and an array, two Sets, or two arrays
|
||||
*
|
||||
* @param mixed $val1
|
||||
* @param mixed $val2
|
||||
* @return array
|
||||
*/
|
||||
function diff($val1, $val2 = null) {
|
||||
if ($val2 == null && (is_a($this, 'set') || is_a($this, 'Set'))) {
|
||||
$val2 = $val1;
|
||||
$val1 = $this->get();
|
||||
}
|
||||
if (is_object($val2) && (is_a($val2, 'set') || is_a($val2, 'Set'))) {
|
||||
|
||||
}
|
||||
|
||||
$out = array();
|
||||
foreach ($val1 as $key => $val) {
|
||||
if (!isset($val2[$key]) || $val2[$key] != $val) {
|
||||
$out[$key] = $val;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* Determines if two Sets or arrays are equal
|
||||
*
|
||||
|
|
|
@ -40,6 +40,10 @@ class PaginatorHelper extends AppHelper {
|
|||
* @var array
|
||||
*/
|
||||
var $helpers = array('Html', 'Ajax');
|
||||
|
||||
var $Html = null;
|
||||
|
||||
var $Ajax = null;
|
||||
/**
|
||||
* Holds the default model for paged recordsets
|
||||
*
|
||||
|
@ -138,12 +142,21 @@ class PaginatorHelper extends AppHelper {
|
|||
$options['step'] *= -1;
|
||||
}
|
||||
$url = am(
|
||||
array_diff_assoc($paging['options'], $paging['defaults']),
|
||||
array('page' => ($paging['options']['page'] + $options['step'])),
|
||||
array_filter(Set::diff($paging['options'], $paging['defaults'])),
|
||||
array('page' => ($paging['page'] + $options['step'])),
|
||||
$url
|
||||
);
|
||||
|
||||
if (isset($url['order'])) {
|
||||
$sort = $direction = null;
|
||||
if (is_array($url['order'])) {
|
||||
list($sort, $direction) = array(preg_replace('/.*\./', '', key($url['order'])), current($url['order']));
|
||||
}
|
||||
unset($url['order']);
|
||||
$url = am($url, compact('sort', 'direction'));
|
||||
}
|
||||
} elseif (is_string($url)) {
|
||||
$url .= '/' . ($paging['options']['page'] + $options['step']);
|
||||
$url .= '/' . ($paging['page'] + $options['step']);
|
||||
}
|
||||
|
||||
if ($this->{$check}()) {
|
||||
|
|
Loading…
Reference in a new issue