Skip to content

Commit

Permalink
Fix notice errors when creating fields named 0.
Browse files Browse the repository at this point in the history
Fixes #3371
  • Loading branch information
markstory committed Nov 15, 2012
1 parent 7206254 commit 58de670
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -2153,6 +2153,23 @@ public function testInput() {
$this->assertTags($result, $expected);
}

/**
* Test that inputs with 0 can be created.
*
* @return void
*/
public function testInputZero() {
$this->Form->create('User');
$result = $this->Form->input('0');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'User0'), '/label',
'input' => array('type' => 'text', 'name' => 'data[User][0]', 'id' => 'User0'),
'/div'
);
$this->assertTags($result, $expected);
}

/**
* test input() with checkbox creation
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -199,7 +199,7 @@ protected function _introspectModel($model, $key, $field = null) {
$this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple');
}
}
if (empty($field)) {
if ($field === null || $field === false) {
return $this->fieldset[$model]['fields'];
} elseif (isset($this->fieldset[$model]['fields'][$field])) {
return $this->fieldset[$model]['fields'][$field];
Expand Down Expand Up @@ -773,7 +773,7 @@ public function error($field, $text = null, $options = array()) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::label
*/
public function label($fieldName = null, $text = null, $options = array()) {
if (empty($fieldName)) {
if ($fieldName === null) {
$fieldName = implode('.', $this->entity());
}

Expand Down

1 comment on commit 58de670

@parkerbossier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Cake!

Please sign in to comment.