diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 199c6a17c..4fa2e3111 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -848,7 +848,12 @@ class Model extends Overloadable { */ function getColumnTypes() { $columns = $this->loadInfo(); - return array_combine($columns->extract('{n}.name'), $columns->extract('{n}.type')); + $names = $columns->extract('{n}.name'); + $types = $columns->extract('{n}.type'); + if (!count($names) || !count($types)) { + trigger_error(__('(Model::getColumnTypes) Unable to build model field data. If you are using a model without a database table, try implementing loadInfo()', true), E_USER_WARNING); + } + return array_combine($names, $types); } /** * Returns the column type of a column in the model @@ -1727,6 +1732,8 @@ class Model extends Overloadable { } $valid = true; + $msg = null; + if (method_exists($this, $rule)) { $ruleParams[] = array_diff_key($validator, $default); $valid = call_user_func_array(array(&$this, $rule), $ruleParams); diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index ffef2953c..59ba33c6a 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -109,9 +109,18 @@ class FormHelper extends AppHelper { if(isset($object)) { $fields = $object->loadInfo(); + $fieldNames = $fields->extract('{n}.name'); + $fieldTypes = $fields->extract('{n}.type'); + $fieldLengths = $fields->extract('{n}.length'); + if (!count($fieldNames) || !count($fieldTypes)) { + trigger_error(__('(FormHelper::create) Unable to use model field data. If you are using a model without a database table, try implementing loadInfo()', true), E_USER_WARNING); + } + if (!count($fieldNames) || !count($fieldLengths) || (count($fieldNames) != count($fieldTypes))) { + trigger_error(__('(FormHelper::create) Unable to use model field data. If you are using a model without a database table, try implementing loadInfo()', true), E_USER_WARNING); + } $data = array( - 'fields' => array_combine($fields->extract('{n}.name'), $fields->extract('{n}.type')), - 'sizes' => array_combine($fields->extract('{n}.name'), $fields->extract('{n}.length')), + 'fields' => array_combine($fieldNames, $fieldTypes), + 'sizes' => array_combine($fieldNames, $fieldLengths), 'key' => $object->primaryKey, 'validates' => (ife(empty($object->validate), array(), array_keys($object->validate))) );