Browse Source

Renamed DetailView attribute type to format

for consistency with GridViews DataColumn where the same property is
also named format
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
c7ef701d8a
  1. 18
      framework/yii/widgets/DetailView.php

18
framework/yii/widgets/DetailView.php

@ -57,8 +57,8 @@ class DetailView extends Widget
* @var array a list of attributes to be displayed in the detail view. Each array element
* represents the specification for displaying one particular attribute.
*
* An attribute can be specified as a string in the format of "Name" or "Name:Type", where "Name" refers to
* the attribute name, and "Type" represents the type of the attribute. The "Type" is passed to the [[Formatter::format()]]
* An attribute can be specified as a string in the format of "Name" or "Name:Format", where "Name" refers to
* the attribute name, and "Format" represents the format of the attribute. The "Format" is passed to the [[Formatter::format()]]
* method to format an attribute value into a displayable text. Please refer to [[Formatter]] for the supported types.
*
* An attribute can also be specified in terms of an array with the following elements:
@ -67,8 +67,8 @@ class DetailView extends Widget
* - label: the label associated with the attribute. If this is not specified, it will be generated from the attribute name.
* - value: the value to be displayed. If this is not specified, it will be retrieved from [[model]] using the attribute name
* by calling [[ArrayHelper::getValue()]]. Note that this value will be formatted into a displayable text
* according to the "type" option.
* - type: the type of the value that determines how the value would be formatted into a displayable text.
* according to the "format" option.
* - format: the type of the value that determines how the value would be formatted into a displayable text.
* Please refer to [[Formatter]] for supported types.
* - visible: whether the attribute is visible. If set to `false`, the attribute will be displayed.
*/
@ -145,7 +145,7 @@ class DetailView extends Widget
if (is_string($this->template)) {
return strtr($this->template, [
'{label}' => $attribute['label'],
'{value}' => $this->formatter->format($attribute['value'], $attribute['type']),
'{value}' => $this->formatter->format($attribute['value'], $attribute['format']),
]);
} else {
return call_user_func($this->template, $attribute, $index, $this);
@ -174,11 +174,11 @@ class DetailView extends Widget
foreach ($this->attributes as $i => $attribute) {
if (is_string($attribute)) {
if (!preg_match('/^(\w+)(\s*:\s*(\w+))?$/', $attribute, $matches)) {
throw new InvalidConfigException('The attribute must be specified in the format of "Name" or "Name:Type"');
throw new InvalidConfigException('The attribute must be specified in the format of "Name" or "Name:Format"');
}
$attribute = [
'name' => $matches[1],
'type' => isset($matches[3]) ? $matches[3] : 'text',
'format' => isset($matches[3]) ? $matches[3] : 'text',
];
}
@ -186,8 +186,8 @@ class DetailView extends Widget
throw new InvalidConfigException('The attribute configuration must be an array.');
}
if (!isset($attribute['type'])) {
$attribute['type'] = 'text';
if (!isset($attribute['format'])) {
$attribute['format'] = 'text';
}
if (isset($attribute['name'])) {
$name = $attribute['name'];

Loading…
Cancel
Save