Final Class Yiisoft\Yii\Widgets\ContentDecorator
| Inheritance | Yiisoft\Yii\Widgets\ContentDecorator » Yiisoft\Widget\Widget |
|---|
ContentDecorator records all output between {@see Widget::begin()} and {@see Widget::end()} calls,
passes it to the given view file as $content and then echoes rendering result.
<?= ContentDecorator::widget()
->viewFile('@app/views/layouts/base.php')
->parameters([])
->begin();
?>
some content here
<?= ContentDecorator::end() ?>
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\Widgets\ContentDecorator | |
| begin() | Starts recording a content. | Yiisoft\Yii\Widgets\ContentDecorator |
| parameters() | Returns a new instance with the specified parameters. | Yiisoft\Yii\Widgets\ContentDecorator |
| render() | Ends recording a content. | Yiisoft\Yii\Widgets\ContentDecorator |
| viewFile() | Returns a new instance with the specified view file. | Yiisoft\Yii\Widgets\ContentDecorator |
Method Details
| public mixed __construct ( \Yiisoft\Aliases\Aliases $aliases, \Yiisoft\View\WebView $webView ) | ||
| $aliases | \Yiisoft\Aliases\Aliases | |
| $webView | \Yiisoft\View\WebView | |
public function __construct(private Aliases $aliases, private WebView $webView)
{
}
Starts recording a content.
| public string|null begin ( ) |
public function begin(): ?string
{
parent::begin();
ob_start();
return null;
}
Returns a new instance with the specified parameters.
| public self parameters ( array $value ) | ||
| $value | array |
The parameters (name => value) to be extracted and made available in the decorative view. |
public function parameters(array $value): self
{
$new = clone $this;
$new->parameters = $value;
return $new;
}
Ends recording a content.
This method stops output buffering and saves the rendering result as a $content
variable and then echoes rendering result.
| public string render ( ) | ||
| return | string |
The result of widget execution to be outputted. |
|---|---|---|
| throws | Throwable|\Yiisoft\View\Exception\ViewNotFoundException | |
public function render(): string
{
$parameters = $this->parameters;
$parameters['content'] = ob_get_clean();
/** render under the existing context */
return $this->webView->render($this->viewFile, $parameters);
}
Returns a new instance with the specified view file.
| public self viewFile ( string $value ) | ||
| $value | string |
The view file that will be used to decorate the content enclosed by this widget. This can be specified as either the view file path or alias path. |
public function viewFile(string $value): self
{
$new = clone $this;
$new->viewFile = $this->aliases->get($value);
return $new;
}
Signup or Login in order to comment.