Adding sanity checking / warning messages for data returned from Model::loadInfo() (thanks phishy)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5027 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-05-05 17:36:30 +00:00
parent 8a3914f8df
commit 360690ed7f
2 changed files with 19 additions and 3 deletions

View file

@ -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);

View file

@ -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)))
);