Dispatcher::parseParams() now works with file uploads that are not indexed by model. Fixes #9

This commit is contained in:
jperras 2009-08-13 11:29:00 -04:00
parent 1a86de5fe3
commit adc198805f
2 changed files with 38 additions and 6 deletions

View file

@ -303,22 +303,28 @@ class Dispatcher extends Object {
$params['url'] = $url;
}
}
foreach ($_FILES as $name => $data) {
if ($name != 'data') {
$params['form'][$name] = $data;
}
}
if (isset($_FILES['data'])) {
foreach ($_FILES['data'] as $key => $data) {
foreach ($data as $model => $fields) {
foreach ($fields as $field => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$params['data'][$model][$field][$k][$key] = $v;
if (is_array($fields)) {
foreach ($fields as $field => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$params['data'][$model][$field][$k][$key] = $v;
}
} else {
$params['data'][$model][$field][$key] = $value;
}
} else {
$params['data'][$model][$field][$key] = $value;
}
} else {
$params['data'][$model][$key] = $fields;
}
}
}

View file

@ -883,6 +883,32 @@ class DispatcherTest extends CakeTestCase {
)
);
$this->assertEqual($result['data'], $expected);
$_FILES = array(
'data' => array(
'name' => array('birth_cert' => 'born on.txt'),
'type' => array('birth_cert' => 'application/octet-stream'),
'tmp_name' => array('birth_cert' => '/private/var/tmp/phpbsUWfH'),
'error' => array('birth_cert' => 0),
'size' => array('birth_cert' => 123)
)
);
$Dispatcher =& new Dispatcher();
$result = $Dispatcher->parseParams('/');
$expected = array(
'birth_cert' => array(
'name' => 'born on.txt',
'type' => 'application/octet-stream',
'tmp_name' => '/private/var/tmp/phpbsUWfH',
'error' => 0,
'size' => 123
)
);
$this->assertEqual($result['data'], $expected);
}
/**
* testGetUrl method