PHP 클래스 yii\widgets\DetailView

DetailView is best used for displaying a model in a regular format (e.g. each model attribute is displayed as a row in a table.) The model can be either an instance of [[Model]] or an associative array. DetailView uses the [[attributes]] property to determines which model attributes should be displayed and how they should be formatted. A typical usage of DetailView is as follows: php echo DetailView::widget([ 'model' => $model, 'attributes' => [ 'title', // title attribute (in plain text) 'description:html', // description attribute in HTML [ // the owner name of the model 'label' => 'Owner', 'value' => $model->owner->name, ], 'created_at:datetime', // creation date formatted as datetime ], ]); For more details and usage information on DetailView, see the guide article on data widgets.
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends yii\base\Widget
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$attributes 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 attribute, attribute:format or attribute:format:label, where attribute 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. Both format and label are optional. They will take default values if absent. An attribute can also be specified in terms of an array with the following elements: - attribute: the attribute name. This is required if either label or value is not specified. - 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 format option. Since version 2.0.11 it can be defined as closure with the following parameters: php function ($model, $widget) $model refers to displayed model and $widget is an instance of DetailView widget. - 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 NOT be displayed. - contentOptions: the HTML attributes to customize value tag. For example: ['class' => 'bg-red']. Please refer to [[\yii\helpers\BaseHtml::renderTagAttributes()]] for the supported syntax. - captionOptions: the HTML attributes to customize label tag. For example: ['class' => 'bg-red']. Please refer to [[\yii\helpers\BaseHtml::renderTagAttributes()]] for the supported syntax.
$formatter the formatter used to format model attribute values into displayable texts. This can be either an instance of [[Formatter]] or an configuration array for creating the [[Formatter]] instance. If this property is not set, the formatter application component will be used.
$model the data model whose details are to be displayed. This can be a [[Model]] instance, an associative array, an object that implements [[Arrayable]] interface or simply an object with defined public accessible non-static properties.
$options the HTML attributes for the container tag of this widget. The tag option specifies what container tag should be used. It defaults to table if not set.
$template the template used to render a single attribute. If a string, the token {label} and {value} will be replaced with the label and the value of the corresponding attribute. If a callback (e.g. an anonymous function), the signature must be as follows: php function ($attribute, $index, $widget) where $attribute refer to the specification of the attribute being rendered, $index is the zero-based index of the attribute in the [[attributes]] array, and $widget refers to this widget instance. Since Version 2.0.10, the tokens {captionOptions} and {contentOptions} are available, which will represent HTML attributes of HTML container elements for the label and value.

공개 메소드들

메소드 설명
init ( ) Initializes the detail view.
run ( ) Renders the detail view.

보호된 메소드들

메소드 설명
normalizeAttributes ( ) Normalizes the attribute specifications.
renderAttribute ( array $attribute, integer $index ) : string Renders a single attribute.

메소드 상세

init() 공개 메소드

This method will initialize required property values.
public init ( )

normalizeAttributes() 보호된 메소드

Normalizes the attribute specifications.
protected normalizeAttributes ( )

renderAttribute() 보호된 메소드

Renders a single attribute.
protected renderAttribute ( array $attribute, integer $index ) : string
$attribute array the specification of the attribute to be rendered.
$index integer the zero-based index of the attribute in the [[attributes]] array
리턴 string the rendering result

run() 공개 메소드

This is the main entry of the whole detail view rendering.
public run ( )

프로퍼티 상세

$attributes 공개적으로 프로퍼티

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 attribute, attribute:format or attribute:format:label, where attribute 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. Both format and label are optional. They will take default values if absent. An attribute can also be specified in terms of an array with the following elements: - attribute: the attribute name. This is required if either label or value is not specified. - 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 format option. Since version 2.0.11 it can be defined as closure with the following parameters: php function ($model, $widget) $model refers to displayed model and $widget is an instance of DetailView widget. - 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 NOT be displayed. - contentOptions: the HTML attributes to customize value tag. For example: ['class' => 'bg-red']. Please refer to [[\yii\helpers\BaseHtml::renderTagAttributes()]] for the supported syntax. - captionOptions: the HTML attributes to customize label tag. For example: ['class' => 'bg-red']. Please refer to [[\yii\helpers\BaseHtml::renderTagAttributes()]] for the supported syntax.
public $attributes

$formatter 공개적으로 프로퍼티

the formatter used to format model attribute values into displayable texts. This can be either an instance of [[Formatter]] or an configuration array for creating the [[Formatter]] instance. If this property is not set, the formatter application component will be used.
public $formatter

$model 공개적으로 프로퍼티

the data model whose details are to be displayed. This can be a [[Model]] instance, an associative array, an object that implements [[Arrayable]] interface or simply an object with defined public accessible non-static properties.
public $model

$options 공개적으로 프로퍼티

the HTML attributes for the container tag of this widget. The tag option specifies what container tag should be used. It defaults to table if not set.
또한 보기: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $options

$template 공개적으로 프로퍼티

the template used to render a single attribute. If a string, the token {label} and {value} will be replaced with the label and the value of the corresponding attribute. If a callback (e.g. an anonymous function), the signature must be as follows: php function ($attribute, $index, $widget) where $attribute refer to the specification of the attribute being rendered, $index is the zero-based index of the attribute in the [[attributes]] array, and $widget refers to this widget instance. Since Version 2.0.10, the tokens {captionOptions} and {contentOptions} are available, which will represent HTML attributes of HTML container elements for the label and value.
public $template