Skip to content
PHP Ecosystem
Explore

DynamicContentAwareTrait

API reference › yii › base › DynamicContentAwareTrait

traityii\base\DynamicContentAwareTrait
Since2.0.14
Sourceframework/base/DynamicContentAwareTrait.php
Used by 2 types

DynamicContentAwareTrait implements common methods for classes which support a View dynamic content feature.

MethodDescriptionDefined by
addDynamicPlaceholder()Adds a placeholder for dynamic content.DynamicContentAwareTrait
getDynamicPlaceholders()Returns a list of placeholders for dynamic content. This method is used internally to implement the content caching feature.DynamicContentAwareTrait
setDynamicPlaceholders()Sets a list of placeholders for dynamic content. This method is used internally to implement the content caching feature.DynamicContentAwareTrait
getView() protected abstractReturns the view object that can be used to render views or view files using dynamic contents.DynamicContentAwareTrait
updateDynamicContent() protectedReplaces placeholders in $content with results of evaluated dynamic statements.DynamicContentAwareTrait
public function addDynamicPlaceholder(mixed $name, mixed $statements): mixed

Adds a placeholder for dynamic content.

This method is used internally to implement the content caching feature.

Parameters

ParameterTypeDescription
$namemixedThe placeholder name.
$statementsmixedThe PHP statements for generating the dynamic content.

Returns

mixed

public function getDynamicPlaceholders(): array

Returns a list of placeholders for dynamic content. This method is used internally to implement the content caching feature.

Returns

array: A list of placeholders.

public function setDynamicPlaceholders(mixed $placeholders): mixed

Sets a list of placeholders for dynamic content. This method is used internally to implement the content caching feature.

Parameters

ParameterTypeDescription
$placeholdersmixedA list of placeholders.

Returns

mixed

abstract protected function getView(): yii\base\View

Returns the view object that can be used to render views or view files using dynamic contents.

Returns

View: The view object that can be used to render views or view files.

protected function updateDynamicContent(string $content, string[] $placeholders, bool $isRestoredFromCache = false): string

Replaces placeholders in $content with results of evaluated dynamic statements.

Parameters

ParameterTypeDescription
$contentstringContent to be parsed.
$placeholdersstring[]Placeholders and their values.
$isRestoredFromCacheboolWhether content is going to be restored from cache.

Returns

string: Final content.