Fix error when no model scope is set

This commit is contained in:
ADmad 2012-12-20 02:32:24 +05:30
parent fe2f56e8bd
commit d16a9ab98e
2 changed files with 23 additions and 1 deletions

View file

@ -3075,6 +3075,25 @@ class FormHelperTest extends CakeTestCase {
$this->Form->create('Contact');
$result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
$this->assertTags($result, $expected);
$this->Form->end();
$this->Form->create(false);
$expected = array(
'fieldset' => array(),
array('div' => array('class' => 'input text')),
'label' => array('for' => 'foo'),
'Foo',
'/label',
'input' => array('type' => 'text', 'name' => 'data[foo]', 'id' => 'foo'),
'*/div',
'/fieldset'
);
$result = $this->Form->inputs(
array('foo' => array('type' => 'text')),
array(),
array('legend' => false)
);
$this->assertTags($result, $expected);
}
/**

View file

@ -833,8 +833,11 @@ class FormHelper extends AppHelper {
*/
public function inputs($fields = null, $blacklist = null, $options = array()) {
$fieldset = $legend = true;
$modelFields = array();
$model = $this->model();
$modelFields = array_keys($this->_introspectModel($model, 'fields'));
if ($model) {
$modelFields = array_keys($this->_introspectModel($model, 'fields'));
}
if (is_array($fields)) {
if (array_key_exists('legend', $fields) && !in_array('legend', $modelFields)) {
$legend = $fields['legend'];