mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
fix form helper, bake, refactor Controller::_selectedArray to just take the association name and checks Controller::data, also made Controller::_selectedArray work for submitted form data and returned model data
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4029 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
79e93c180e
commit
8657757bde
3 changed files with 29 additions and 19 deletions
|
@ -702,7 +702,7 @@ class Controller extends Object {
|
|||
switch($type) {
|
||||
case "text":
|
||||
$fieldNames[$column['name']]['type'] = 'textarea';
|
||||
$fieldNames[$column['name']]['cols'] = '60';
|
||||
$fieldNames[$column['name']]['cols'] = '30';
|
||||
$fieldNames[$column['name']]['rows'] = '10';
|
||||
break;
|
||||
case "string":
|
||||
|
@ -718,7 +718,6 @@ class Controller extends Object {
|
|||
}
|
||||
} else {
|
||||
$fieldNames[$column['name']]['type'] = 'text';
|
||||
$fieldNames[$column['name']]['size'] = '60';
|
||||
}
|
||||
break;
|
||||
case "boolean":
|
||||
|
@ -753,7 +752,6 @@ class Controller extends Object {
|
|||
$enum = trim($enum, "'");
|
||||
$fieldNames[$column['name']]['options'][$enum] = $enum;
|
||||
}
|
||||
|
||||
$fieldNames[$column['name']]['selected'] = $data[$model][$column['name']];
|
||||
break;
|
||||
case "date":
|
||||
|
@ -777,11 +775,10 @@ class Controller extends Object {
|
|||
}
|
||||
|
||||
foreach($modelObj->hasAndBelongsToMany as $associationName => $assocData) {
|
||||
$otherModelClass = $associationName;
|
||||
$otherModelKey = Inflector::underscore($associationName);
|
||||
$otherModelObj = &ClassRegistry::getObject($otherModelKey);
|
||||
if ($doCreateOptions) {
|
||||
$fieldNames[$otherModelKey]['model'] = $otherModelClass;
|
||||
$fieldNames[$otherModelKey]['model'] = $associationName;
|
||||
$fieldNames[$otherModelKey]['label'] = "Related " . Inflector::humanize(Inflector::pluralize($otherModelClass));
|
||||
$fieldNames[$otherModelKey]['prompt'] = $fieldNames[$otherModelKey]['label'];
|
||||
$fieldNames[$otherModelKey]['type'] = "select";
|
||||
|
@ -1101,6 +1098,15 @@ class Controller extends Object {
|
|||
* @return unknown
|
||||
*/
|
||||
function _selectedArray($data, $key = 'id') {
|
||||
if(!is_array($data)) {
|
||||
$model = $data;
|
||||
if(!empty($this->data[$model][$model])) {
|
||||
return $this->data[$model][$model];
|
||||
}
|
||||
if(!empty($this->data[$model])) {
|
||||
$data = $this->data[$model];
|
||||
}
|
||||
}
|
||||
$array = array();
|
||||
if(!empty($data)) {
|
||||
foreach($data as $var) {
|
||||
|
@ -1108,7 +1114,7 @@ class Controller extends Object {
|
|||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -250,10 +250,10 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
|
||||
$selected = null;
|
||||
if (isset($options['selected'])) {
|
||||
if (array_key_exists('selected', $options)) {
|
||||
$selected = $options['selected'];
|
||||
unset($options['selected']);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($options['type']) {
|
||||
case 'hidden':
|
||||
|
@ -277,7 +277,7 @@ class FormHelper extends AppHelper {
|
|||
$list = (isset($options['options']) ? $options['options'] : array());
|
||||
$empty = (isset($options['empty']) ? $options['empty'] : '');
|
||||
unset($options['options'], $options['empty']);
|
||||
$out .= $this->select($tagName, $list, null, $options, $empty);
|
||||
$out .= $this->select($tagName, $list, $selected, $options, $empty);
|
||||
break;
|
||||
case 'time':
|
||||
$out .= $this->Html->dateTimeOptionTag($tagName, null, '12', $selected, $options, null, false);
|
||||
|
@ -289,7 +289,8 @@ class FormHelper extends AppHelper {
|
|||
$out .= $this->Html->dateTimeOptionTag($tagName, 'MDY', '12', $selected, $options, null, false);
|
||||
break;
|
||||
case 'submit':
|
||||
$out .= $this->Html->submit($label);
|
||||
$divOptions['class'] = 'submit';
|
||||
$out = $this->Html->submit($label);
|
||||
break;
|
||||
case 'textarea':
|
||||
default:
|
||||
|
@ -352,12 +353,14 @@ class FormHelper extends AppHelper {
|
|||
$htmlAttributes = $this->__value($htmlAttributes, $fieldName);
|
||||
$htmlAttributes = $this->domId($htmlAttributes);
|
||||
|
||||
if (isset($htmlAttributes['type'])) {
|
||||
unset($htmlAttributes['type']);
|
||||
}
|
||||
$value = null;
|
||||
if (!empty($htmlAttributes['value'])) {
|
||||
if (array_key_exists('value', $htmlAttributes)) {
|
||||
$value = $htmlAttributes['value'];
|
||||
unset($htmlAttributes['value']);
|
||||
}
|
||||
|
||||
if ($this->tagIsInvalid()) {
|
||||
$htmlAttributes = $this->addClass($htmlAttributes, 'form-error');
|
||||
}
|
||||
|
@ -446,14 +449,18 @@ class FormHelper extends AppHelper {
|
|||
if(!is_array($options)) {
|
||||
$options = array();
|
||||
}
|
||||
if (isset($attributes['type'])) {
|
||||
unset($attributes['type']);
|
||||
}
|
||||
if (isset($attributes['showParents']) && $attributes['showParents']) {
|
||||
unset($attributes['showParents']);
|
||||
$showParents = true;
|
||||
}
|
||||
|
||||
|
||||
if (!isset($selected)) {
|
||||
$selected = $this->__value($fieldName);
|
||||
}
|
||||
|
||||
if (isset($attributes) && array_key_exists("multiple", $attributes)) {
|
||||
$tag = $this->Html->tags['selectmultiplestart'];
|
||||
} else {
|
||||
|
|
|
@ -1436,8 +1436,7 @@ class Bake {
|
|||
$otherPluralName = $this->__pluralName($associationName);
|
||||
$selectedOtherPluralName = 'selected' . ucfirst($otherPluralName);
|
||||
$actions .= "\t\t\t\t\$this->set('{$otherPluralName}', \$this->{$currentModelName}->{$otherModelName}->generateList());\n";
|
||||
$actions .= "\t\t\t\tif(empty(\$this->data['{$associationName}']['{$associationName}'])) { \$this->data['{$associationName}']['{$associationName}'] = null; }\n";
|
||||
$actions .= "\t\t\t\t\$this->set('{$selectedOtherPluralName}', \$this->data['{$associationName}']['{$associationName}']);\n";
|
||||
$actions .= "\t\t\t\t\$this->set('{$selectedOtherPluralName}', \$this->_selectedArray('{$associationName}'));\n";
|
||||
}
|
||||
}
|
||||
foreach($modelObj->belongsTo as $associationName => $relation) {
|
||||
|
@ -1474,8 +1473,7 @@ class Bake {
|
|||
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
||||
$selectedOtherPluralName = 'selected' . ucfirst($otherPluralName);
|
||||
$actions .= "\t\t\t\$this->set('{$otherPluralName}', \$this->{$currentModelName}->{$otherModelName}->generateList());\n";
|
||||
$actions .= "\t\t\tif(empty(\$this->data['{$associationName}'])) { \$this->data['{$associationName}'] = null; }\n";
|
||||
$actions .= "\t\t\t\$this->set('{$selectedOtherPluralName}', \$this->_selectedArray(\$this->data['{$associationName}']));\n";
|
||||
$actions .= "\t\t\t\$this->set('{$selectedOtherPluralName}', \$this->_selectedArray('{$associationName}'));\n";
|
||||
}
|
||||
}
|
||||
foreach($modelObj->belongsTo as $associationName => $relation) {
|
||||
|
@ -1507,8 +1505,7 @@ class Bake {
|
|||
$otherPluralName = $this->__pluralName($associationName);
|
||||
$selectedOtherPluralName = 'selected' . ucfirst($otherPluralName);
|
||||
$actions .= "\t\t\t\t\$this->set('{$otherPluralName}', \$this->{$currentModelName}->{$otherModelName}->generateList());\n";
|
||||
$actions .= "\t\t\t\tif(empty(\$this->data['{$associationName}']['{$associationName}'])) { \$this->data['{$associationName}']['{$associationName}'] = null; }\n";
|
||||
$actions .= "\t\t\t\t\$this->set('{$selectedOtherPluralName}', \$this->data['{$associationName}']['{$associationName}']);\n";
|
||||
$actions .= "\t\t\t\t\$this->set('{$selectedOtherPluralName}', \$this->_selectedArray('{$associationName}'));\n";
|
||||
}
|
||||
}
|
||||
foreach($modelObj->belongsTo as $associationName => $relation) {
|
||||
|
|
Loading…
Reference in a new issue