Final Class Yiisoft\Yii\DataView\DetailView\DetailView
| Inheritance | Yiisoft\ |
|---|
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
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| append() | Returns a new instance with HTML content to be added before the closing container tag. | Yiisoft\ |
| containerAttributes() | Returns a new instance with the HTML attributes for container. | Yiisoft\ |
| containerTag() | Returns a new instance with the HTML tag name for the container. | Yiisoft\ |
| data() | Return a new instance with the data. | Yiisoft\ |
| fieldAppend() | Add HTML content after the field container tag. | Yiisoft\ |
| fieldAttributes() | Returns a new instance with the HTML attributes for the field container tag set. | Yiisoft\ |
| fieldPrepend() | Yiisoft\ |
|
| fieldTag() | Returns a new instance with the HTML tag name for the field container. | Yiisoft\ |
| fieldTemplate() | Return a new instance with the field template set. | Yiisoft\ |
| fields() | Return a new instance with the specified fields configuration. | Yiisoft\ |
| labelAppend() | Returns a new instance with the HTML content to be appended to the label. | Yiisoft\ |
| labelAttributes() | Returns a new instance with the HTML attributes for the field label. | Yiisoft\ |
| labelPrepend() | Returns a new instance with the HTML content to be prepended to the label. | Yiisoft\ |
| labelTag() | Returns a new instance with the HTML tag name for the field label wrapper. | Yiisoft\ |
| listAttributes() | Returns a new instance with the HTML attributes for the list set. | Yiisoft\ |
| listTag() | Returns a new instance with the HTML tag name for the list. | Yiisoft\ |
| prepend() | Returns a new instance with HTML content to be added after the opening container tag. | Yiisoft\ |
| render() | Yiisoft\ |
|
| valueAppend() | Returns a new instance with the HTML content to be appended to the value. | Yiisoft\ |
| valueAttributes() | Returns a new instance with the HTML attributes for the value tag. | Yiisoft\ |
| valuePrepend() | Returns a new instance with the HTML content to be prepended to the value. | Yiisoft\ |
| valuePresenter() | Returns a new instance with the value presenter set. | Yiisoft\ |
| valueTag() | Return a new instance with the value tag. | Yiisoft\ |
Method Details
| public mixed __construct ( ) |
public function __construct()
{
$this->valuePresenter = new SimpleValuePresenter();
}
Returns a new instance with HTML content to be added before the closing container tag.
| public self append ( string|\ | ||
| $append | string|\ |
The HTML content to be appended. |
public function append(string|Stringable ...$append): self
{
$new = clone $this;
$new->append = implode('', $append);
return $new;
}
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;
}
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;
}
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;
}
Add HTML content after the field container tag.
| public $this fieldAppend ( string|\ | ||
| $append | string|\ |
The HTML content to be appended. |
public function fieldAppend(string|Stringable ...$append): self
{
$new = clone $this;
$new->fieldAppend = implode('', $append);
return $new;
}
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;
}
| public self fieldPrepend ( string|\ | ||
| $prepend | string|\ |
|
public function fieldPrepend(string|Stringable ...$prepend): self
{
$new = clone $this;
$new->fieldPrepend = implode('', $prepend);
return $new;
}
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;
}
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;
}
Return a new instance with the specified fields configuration.
| public self fields ( Yiisoft\ | ||
| $fields | Yiisoft\ |
The field configurations. Each object represents the configuration for one particular field. For example,
|
public function fields(DataField ...$fields): self
{
$new = clone $this;
$new->fields = $fields;
return $new;
}
Returns a new instance with the HTML content to be appended to the label.
| public self labelAppend ( string|\ | ||
| $append | string|\ |
The HTML content to be appended. |
public function labelAppend(string|Stringable ...$append): self
{
$new = clone $this;
$new->labelAppend = implode('', $append);
return $new;
}
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;
}
Returns a new instance with the HTML content to be prepended to the label.
| public self labelPrepend ( string|\ | ||
| $prepend | string|\ |
The HTML content to be prepended. |
public function labelPrepend(string|Stringable ...$prepend): self
{
$new = clone $this;
$new->labelPrepend = implode('', $prepend);
return $new;
}
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 |
public function labelTag(?string $tag): self
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->labelTag = $tag;
return $new;
}
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;
}
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;
}
Returns a new instance with HTML content to be added after the opening container tag.
| public self prepend ( string|\ | ||
| $prepend | string|\ |
The HTML content to be prepended. |
public function prepend(string|Stringable ...$prepend): self
{
$new = clone $this;
$new->prepend = implode('', $prepend);
return $new;
}
| 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();
}
Returns a new instance with the HTML content to be appended to the value.
| public self valueAppend ( string|\ | ||
| $append | string|\ |
The HTML content to be appended. |
public function valueAppend(string|Stringable ...$append): self
{
$new = clone $this;
$new->valueAppend = implode('', $append);
return $new;
}
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;
}
Returns a new instance with the HTML content to be prepended to the value.
| public self valuePrepend ( string|\ | ||
| $prepend | string|\ |
The HTML content to be prepended. |
public function valuePrepend(string|Stringable ...$prepend): self
{
$new = clone $this;
$new->valuePrepend = implode('', $prepend);
return $new;
}
Returns a new instance with the value presenter set.
| public self valuePresenter ( Yiisoft\ | ||
| $presenter | Yiisoft\ |
The value presenter. |
public function valuePresenter(ValuePresenterInterface $presenter): self
{
$new = clone $this;
$new->valuePresenter = $presenter;
return $new;
}
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;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.