diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 6207c8529..1c2eada66 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -328,8 +328,8 @@ class Helper extends Overloadable { $sameScope = $hasField = false; $parts = preg_split('/\/|\./', $entity); - $model = $view->model; + if(count($parts) === 1 || is_numeric($parts[0])) { $sameScope = true; } else { @@ -350,11 +350,15 @@ class Helper extends Overloadable { } } - if($sameScope === true && in_array($parts[0], array_keys($ModelObj->hasAndBelongsToMany))) { + if ($sameScope === true && in_array($parts[0], array_keys($ModelObj->hasAndBelongsToMany))) { $sameScope = false; } } + if ($parts[0] == $view->field && $view->field != $view->model) { + array_unshift($parts, $model); + $hasField = true; + } $view->field = $view->modelId = $view->fieldSuffix = $view->association = null; switch (count($parts)) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 51d273f4d..9f62b416e 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -1019,6 +1019,17 @@ class FormHelperTest extends CakeTestCase { $this->Form->data['Model']['field'] = '2008-01-01 00:00:00'; $result = $this->Form->dateTime('Model.field', 'DMY', '12', null, array(), false); $this->assertPattern('/option value="12" selected="selected"/', $result); + + $this->Form->create('Contact'); + $result = $this->Form->input('published'); + $this->assertPattern('/name="data\[Contact\]\[published\]\[month\]"/', $result); + $this->assertPattern('/name="data\[Contact\]\[published\]\[day\]"/', $result); + $this->assertPattern('/name="data\[Contact\]\[published\]\[year\]"/', $result); + + $result = $this->Form->input('published2', array('type' => 'date')); + $this->assertPattern('/name="data\[Contact\]\[published2\]\[month\]"/', $result); + $this->assertPattern('/name="data\[Contact\]\[published2\]\[day\]"/', $result); + $this->assertPattern('/name="data\[Contact\]\[published2\]\[year\]"/', $result); } function testMonth() {