0 follower

Final Class Yiisoft\Yii\DataView\DetailView\DetailView

InheritanceYiisoft\Yii\DataView\DetailView\DetailView » Yiisoft\Widget\Widget

DetailView displays details about a single data item. The data can be either an object or an associative array.

Which fields should be displayed and how exactly is determined by "fields":

<?= DetailView::widget()
    ->data(['id' => 1, 'username' => 'tests 1', 'status' => true])
    ->fields(
        new DataField('id'),
        new DataField('username'),
        new DataField('status'),
    )
?>

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Yii\DataView\DetailView\DetailView
append() Returns a new instance with HTML content to be added before the closing container tag. Yiisoft\Yii\DataView\DetailView\DetailView
containerAttributes() Returns a new instance with the HTML attributes for container. Yiisoft\Yii\DataView\DetailView\DetailView
containerTag() Returns a new instance with the HTML tag name for the container. Yiisoft\Yii\DataView\DetailView\DetailView
data() Return a new instance with the data. Yiisoft\Yii\DataView\DetailView\DetailView
fieldAppend() Add HTML content after the field container tag. Yiisoft\Yii\DataView\DetailView\DetailView
fieldAttributes() Returns a new instance with the HTML attributes for the field container tag set. Yiisoft\Yii\DataView\DetailView\DetailView
fieldPrepend() Yiisoft\Yii\DataView\DetailView\DetailView
fieldTag() Returns a new instance with the HTML tag name for the field container. Yiisoft\Yii\DataView\DetailView\DetailView
fieldTemplate() Return a new instance with the field template set. Yiisoft\Yii\DataView\DetailView\DetailView
fields() Return a new instance with the specified fields configuration. Yiisoft\Yii\DataView\DetailView\DetailView
labelAppend() Returns a new instance with the HTML content to be appended to the label. Yiisoft\Yii\DataView\DetailView\DetailView
labelAttributes() Returns a new instance with the HTML attributes for the field label. Yiisoft\Yii\DataView\DetailView\DetailView
labelPrepend() Returns a new instance with the HTML content to be prepended to the label. Yiisoft\Yii\DataView\DetailView\DetailView
labelTag() Returns a new instance with the HTML tag name for the field label wrapper. Yiisoft\Yii\DataView\DetailView\DetailView
listAttributes() Returns a new instance with the HTML attributes for the list set. Yiisoft\Yii\DataView\DetailView\DetailView
listTag() Returns a new instance with the HTML tag name for the list. Yiisoft\Yii\DataView\DetailView\DetailView
prepend() Returns a new instance with HTML content to be added after the opening container tag. Yiisoft\Yii\DataView\DetailView\DetailView
render() Yiisoft\Yii\DataView\DetailView\DetailView
valueAppend() Returns a new instance with the HTML content to be appended to the value. Yiisoft\Yii\DataView\DetailView\DetailView
valueAttributes() Returns a new instance with the HTML attributes for the value tag. Yiisoft\Yii\DataView\DetailView\DetailView
valuePrepend() Returns a new instance with the HTML content to be prepended to the value. Yiisoft\Yii\DataView\DetailView\DetailView
valuePresenter() Returns a new instance with the value presenter set. Yiisoft\Yii\DataView\DetailView\DetailView
valueTag() Return a new instance with the value tag. Yiisoft\Yii\DataView\DetailView\DetailView

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( )

                public function __construct()
{
    $this->valuePresenter = new SimpleValuePresenter();
}

            
append() public method

Returns a new instance with HTML content to be added before the closing container tag.

public self append ( string|\Stringable $append )
$append string|\Stringable

The HTML content to be appended.

                public function append(string|Stringable ...$append): self
{
    $new = clone $this;
    $new->append = implode('', $append);
    return $new;
}

            
containerAttributes() public method

Returns a new instance with the HTML attributes for container.

public self containerAttributes ( array $attributes )
$attributes array

Attribute values indexed by attribute names.

                public function containerAttributes(array $attributes): self
{
    $new = clone $this;
    $new->containerAttributes = $attributes;
    return $new;
}

            
containerTag() public method

Returns a new instance with the HTML tag name for the container.

public self containerTag ( string|null $tag )
$tag string|null

HTML tag name.

                public function containerTag(?string $tag): self
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->containerTag = $tag;
    return $new;
}

            
data() public method

Return a new instance with the data.

public self data ( array|object $data )
$data array|object

The data model whose details are to be displayed. This can be an object or an associative array.

                public function data(array|object $data): self
{
    $new = clone $this;
    $new->data = $data;
    return $new;
}

            
fieldAppend() public method

Add HTML content after the field container tag.

public $this fieldAppend ( string|\Stringable $append )
$append string|\Stringable

The HTML content to be appended.

                public function fieldAppend(string|Stringable ...$append): self
{
    $new = clone $this;
    $new->fieldAppend = implode('', $append);
    return $new;
}

            
fieldAttributes() public method

Returns a new instance with the HTML attributes for the field container tag set.

public self fieldAttributes ( array|Closure $attributes )
$attributes array|Closure

Attribute values indexed by attribute names.

                public function fieldAttributes(array|Closure $attributes): self
{
    $new = clone $this;
    $new->fieldAttributes = $attributes;
    return $new;
}

            
fieldPrepend() public method

public self fieldPrepend ( string|\Stringable $prepend )
$prepend string|\Stringable

                public function fieldPrepend(string|Stringable ...$prepend): self
{
    $new = clone $this;
    $new->fieldPrepend = implode('', $prepend);
    return $new;
}

            
fieldTag() public method

Returns a new instance with the HTML tag name for the field container.

public self fieldTag ( string|null $tag )
$tag string|null

The HTML tag name.

                public function fieldTag(?string $tag): self
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->fieldTag = $tag;
    return $new;
}

            
fieldTemplate() public method

Return a new instance with the field template set.

Available placeholders are {label} and {value}.

public self fieldTemplate ( string $template )
$template string

The field template.

                public function fieldTemplate(string $template): self
{
    $new = clone $this;
    $new->fieldTemplate = $template;
    return $new;
}

            
fields() public method

Return a new instance with the specified fields configuration.

public self fields ( Yiisoft\Yii\DataView\DetailView\DataField $fields )
$fields Yiisoft\Yii\DataView\DetailView\DataField

The field configurations. Each object represents the configuration for one particular field. For example,

[
   new DataField('name', label: 'Name'),
]

                public function fields(DataField ...$fields): self
{
    $new = clone $this;
    $new->fields = $fields;
    return $new;
}

            
labelAppend() public method

Returns a new instance with the HTML content to be appended to the label.

public self labelAppend ( string|\Stringable $append )
$append string|\Stringable

The HTML content to be appended.

                public function labelAppend(string|Stringable ...$append): self
{
    $new = clone $this;
    $new->labelAppend = implode('', $append);
    return $new;
}

            
labelAttributes() public method

Returns a new instance with the HTML attributes for the field label.

public self labelAttributes ( array|Closure $attributes )
$attributes array|Closure

Attribute values indexed by attribute names.

                public function labelAttributes(array|Closure $attributes): self
{
    $new = clone $this;
    $new->labelAttributes = $attributes;
    return $new;
}

            
labelPrepend() public method

Returns a new instance with the HTML content to be prepended to the label.

public self labelPrepend ( string|\Stringable $prepend )
$prepend string|\Stringable

The HTML content to be prepended.

                public function labelPrepend(string|Stringable ...$prepend): self
{
    $new = clone $this;
    $new->labelPrepend = implode('', $prepend);
    return $new;
}

            
labelTag() public method

Returns a new instance with the HTML tag name for the field label wrapper.

public self labelTag ( string|null $tag )
$tag string|null

The HTML tag name or null to disable the wrapper.

                public function labelTag(?string $tag): self
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->labelTag = $tag;
    return $new;
}

            
listAttributes() public method

Returns a new instance with the HTML attributes for the list set.

public self listAttributes ( array $attributes )
$attributes array

Attribute values indexed by attribute names.

                public function listAttributes(array $attributes): self
{
    $new = clone $this;
    $new->listAttributes = $attributes;
    return $new;
}

            
listTag() public method

Returns a new instance with the HTML tag name for the list.

public self listTag ( string|null $tag )
$tag string|null

The HTML tag name.

                public function listTag(?string $tag): self
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->listTag = $tag;
    return $new;
}

            
prepend() public method

Returns a new instance with HTML content to be added after the opening container tag.

public self prepend ( string|\Stringable $prepend )
$prepend string|\Stringable

The HTML content to be prepended.

                public function prepend(string|Stringable ...$prepend): self
{
    $new = clone $this;
    $new->prepend = implode('', $prepend);
    return $new;
}

            
render() public method

public string render ( )

                public function render(): string
{
    $content = $this->renderList();
    if ($content === '') {
        return '';
    }
    if ($this->prepend !== '') {
        $content = $this->prepend . "\n" . $content;
    }
    if ($this->append !== '') {
        $content .= "\n" . $this->append;
    }
    return $this->containerTag === null
        ? $content
        : Html::tag($this->containerTag, "\n" . $content . "\n", $this->containerAttributes)
            ->encode(false)
            ->render();
}

            
valueAppend() public method

Returns a new instance with the HTML content to be appended to the value.

public self valueAppend ( string|\Stringable $append )
$append string|\Stringable

The HTML content to be appended.

                public function valueAppend(string|Stringable ...$append): self
{
    $new = clone $this;
    $new->valueAppend = implode('', $append);
    return $new;
}

            
valueAttributes() public method

Returns a new instance with the HTML attributes for the value tag.

public self valueAttributes ( array|Closure $attributes )
$attributes array|Closure

Attribute values indexed by attribute names.

                public function valueAttributes(array|Closure $attributes): self
{
    $new = clone $this;
    $new->valueAttributes = $attributes;
    return $new;
}

            
valuePrepend() public method

Returns a new instance with the HTML content to be prepended to the value.

public self valuePrepend ( string|\Stringable $prepend )
$prepend string|\Stringable

The HTML content to be prepended.

                public function valuePrepend(string|Stringable ...$prepend): self
{
    $new = clone $this;
    $new->valuePrepend = implode('', $prepend);
    return $new;
}

            
valuePresenter() public method

Returns a new instance with the value presenter set.

public self valuePresenter ( Yiisoft\Yii\DataView\ValuePresenter\ValuePresenterInterface $presenter )
$presenter Yiisoft\Yii\DataView\ValuePresenter\ValuePresenterInterface

The value presenter.

                public function valuePresenter(ValuePresenterInterface $presenter): self
{
    $new = clone $this;
    $new->valuePresenter = $presenter;
    return $new;
}

            
valueTag() public method

Return a new instance with the value tag.

public self valueTag ( string|null $tag )
$tag string|null

HTML tag.

                public function valueTag(?string $tag): self
{
    if ($tag === '') {
        throw new InvalidArgumentException('Tag name cannot be empty.');
    }
    $new = clone $this;
    $new->valueTag = $tag;
    return $new;
}