Interface Yiisoft\View\ViewInterface
| Implemented by | Yiisoft\View\View, Yiisoft\View\WebView |
|---|
View allows rendering templates and sub-templates using data provided.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| addToParameter() | Add values to end of common array parameter. If specified parameter does not exist or him is not array, then parameter will be added as empty array. | Yiisoft\View\ViewInterface |
| clear() | Clears the data for working with the event loop. | Yiisoft\View\ViewInterface |
| deepClone() | Returns a new instance with deep clone of the object, including state cloning. | Yiisoft\View\ViewInterface |
| getBasePath() | Gets the base path to the view directory. | Yiisoft\View\ViewInterface |
| getBlock() | Gets content of the block by ID. | Yiisoft\View\ViewInterface |
| getLocale() | Get the specified locale code. | Yiisoft\View\ViewInterface |
| getParameter() | Gets a common parameter value by ID. | Yiisoft\View\ViewInterface |
| getPlaceholderSignature() | Gets the placeholder signature. | Yiisoft\View\ViewInterface |
| getTheme() | Gets the theme instance, or null if no theme has been set. |
Yiisoft\View\ViewInterface |
| getViewFile() | Gets the view file currently being rendered. | Yiisoft\View\ViewInterface |
| hasBlock() | Checks the existence of a content block by ID. | Yiisoft\View\ViewInterface |
| hasParameter() | Checks the existence of a common parameter by ID. | Yiisoft\View\ViewInterface |
| localize() | Returns the localized version of a specified file. | Yiisoft\View\ViewInterface |
| removeBlock() | Removes a content block. | Yiisoft\View\ViewInterface |
| removeParameter() | Removes a common parameter. | Yiisoft\View\ViewInterface |
| render() | Renders a view. | Yiisoft\View\ViewInterface |
| setBlock() | Sets a content block. | Yiisoft\View\ViewInterface |
| setLocale() | Set the specified locale code. | Yiisoft\View\ViewInterface |
| setParameter() | Sets a common parameter that is accessible in all view templates. | Yiisoft\View\ViewInterface |
| setParameters() | Sets a common parameters that is accessible in all view templates. | Yiisoft\View\ViewInterface |
| setTheme() | Set the specified theme instance. | Yiisoft\View\ViewInterface |
| withBasePath() | Returns a new instance with specified base path to the view directory. | Yiisoft\View\ViewInterface |
| withClearedState() | Returns a new instance with cleared state (blocks, parameters, etc.) | Yiisoft\View\ViewInterface |
| withContext() | Returns a new instance with the specified view context instance. | Yiisoft\View\ViewInterface |
| withContextPath() | Returns a new instance with the specified view context path. | Yiisoft\View\ViewInterface |
| withLocale() | Set the specified locale code. | Yiisoft\View\ViewInterface |
| withPlaceholderSalt() | Returns a new instance with specified salt for the placeholder signature {@see getPlaceholderSignature()}. | Yiisoft\View\ViewInterface |
| withRenderers() | Returns a new instance with the specified renderers. | Yiisoft\View\ViewInterface |
| withSourceLocale() | Returns a new instance with the specified source locale. | Yiisoft\View\ViewInterface |
| withTheme() | Set the specified theme instance immutable. | Yiisoft\View\ViewInterface |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| PHP_EXTENSION | 'php' | Yiisoft\View\ViewInterface |
Method Details
Add values to end of common array parameter. If specified parameter does not exist or him is not array, then parameter will be added as empty array.
| public abstract Yiisoft\View\ViewInterface addToParameter ( string $id, mixed $value ) | ||
| $id | string |
The unique identifier of the parameter. |
| $value | mixed |
Value(s) for add to end of array parameter. |
| throws | InvalidArgumentException |
When specified parameter already exists and is not an array. |
|---|---|---|
public function addToParameter(string $id, mixed ...$value): static;
Clears the data for working with the event loop.
| public abstract void clear ( ) |
public function clear(): void;
Returns a new instance with deep clone of the object, including state cloning.
| public abstract Yiisoft\View\ViewInterface deepClone ( ) |
public function deepClone(): static;
Gets the base path to the view directory.
| public abstract string getBasePath ( ) | ||
| return | string |
The base view path. |
|---|---|---|
public function getBasePath(): string;
Gets content of the block by ID.
| public abstract string getBlock ( string $id ) | ||
| $id | string |
The unique identifier of the block. |
| return | string |
The content of the block. |
|---|---|---|
public function getBlock(string $id): string;
Get the specified locale code.
| public abstract string getLocale ( ) | ||
| return | string |
The locale code. |
|---|---|---|
public function getLocale(): string;
Gets a common parameter value by ID.
| public abstract mixed getParameter ( string $id, mixed $default ) | ||
| $id | string |
The unique identifier of the parameter. |
| $default | mixed |
The default value to be returned if the specified parameter does not exist. |
| return | mixed |
The value of the parameter. |
|---|---|---|
| throws | InvalidArgumentException |
If specified parameter does not exist and not passed default value. |
public function getParameter(string $id, mixed ...$default): mixed;
Gets the placeholder signature.
| public abstract string getPlaceholderSignature ( ) | ||
| return | string |
The placeholder signature. |
|---|---|---|
public function getPlaceholderSignature(): string;
Gets the theme instance, or null if no theme has been set.
| public abstract Yiisoft\View\Theme|null getTheme ( ) | ||
| return | Yiisoft\View\Theme|null |
The theme instance, or |
|---|---|---|
public function getTheme(): ?Theme;
Gets the view file currently being rendered.
| public abstract string|null getViewFile ( ) | ||
| return | string|null |
The view file currently being rendered. |
|---|---|---|
public function getViewFile(): ?string;
Checks the existence of a content block by ID.
| public abstract boolean hasBlock ( string $id ) | ||
| $id | string |
The unique identifier of the block. |
| return | boolean |
Whether a content block exists. |
|---|---|---|
public function hasBlock(string $id): bool;
Checks the existence of a common parameter by ID.
| public abstract boolean hasParameter ( string $id ) | ||
| $id | string |
The unique identifier of the parameter. |
| return | boolean |
Whether a custom parameter that is common for all view templates exists. |
|---|---|---|
public function hasParameter(string $id): bool;
Returns the localized version of a specified file.
The searching is based on the specified locale code. In particular, a file with the same name will be looked for under the subdirectory whose name is the same as the locale code. For example, given the file "path/to/view.php" and locale code "zh-CN", the localized file will be looked for as "path/to/zh-CN/view.php". If the file is not found, it will try a fallback with just a locale code that is "zh" i.e. "path/to/zh/view.php". If it is not found as well the original file will be returned.
If the target and the source locale codes are the same, the original file will be returned.
| public abstract string localize ( string $file, string|null $locale = null, string|null $sourceLocale = null ) | ||
| $file | string |
The original file |
| $locale | string|null |
The target locale that the file should be localized to. |
| $sourceLocale | string|null |
The locale that the original file is in. |
| return | string |
The matching localized file, or the original file if the localized version is not found. If the target and the source locale codes are the same, the original file will be returned. |
|---|---|---|
public function localize(string $file, ?string $locale = null, ?string $sourceLocale = null): string;
Removes a content block.
| public abstract Yiisoft\View\ViewInterface removeBlock ( string $id ) | ||
| $id | string |
The unique identifier of the block. |
public function removeBlock(string $id): static;
Removes a common parameter.
| public abstract Yiisoft\View\ViewInterface removeParameter ( string $id ) | ||
| $id | string |
The unique identifier of the parameter. |
public function removeParameter(string $id): static;
Renders a view.
The view to be rendered can be specified in one of the following formats:
- the absolute path to the view file, e.g. "/path/to/view.php";
- the name of the view starting with
//to join the base path {@see \Yiisoft\View\getBasePath()}, e.g. "//site/index"; - the name of the view starting with
./to join the directory containing the view currently being rendered (i.e., this happens when rendering a view within another view), e.g. "./widget"; - the name of the view without the starting
//or./(e.g. "site/index"). The corresponding view file will be looked for under the {@see \Yiisoft\View\ViewContextInterface::getViewPath()} of the context set via {@see \Yiisoft\View\withContext()}. If the context instance was not set {@see \Yiisoft\View\withContext()}, it will be looked for under the base path.
| public abstract string render ( string $view, array $parameters = [] ) | ||
| $view | string |
The view name. |
| $parameters | array |
The parameters (name-value pairs) that will be extracted and made available in the view file. |
| return | string |
The rendering result. |
|---|---|---|
| throws | LogicException |
If the view cannot be resolved. |
| throws | Yiisoft\View\Exception\ViewNotFoundException |
If the view file does not exist. |
| throws | Throwable | |
public function render(string $view, array $parameters = []): string;
Sets a content block.
| public abstract Yiisoft\View\ViewInterface setBlock ( string $id, string $content ) | ||
| $id | string |
The unique identifier of the block. |
| $content | string |
The content of the block. |
public function setBlock(string $id, string $content): static;
Set the specified locale code.
| public abstract Yiisoft\View\ViewInterface setLocale ( string $locale ) | ||
| $locale | string |
The locale code. |
public function setLocale(string $locale): static;
Sets a common parameter that is accessible in all view templates.
| public abstract Yiisoft\View\ViewInterface setParameter ( string $id, mixed $value ) | ||
| $id | string |
The unique identifier of the parameter. |
| $value | mixed |
The value of the parameter. |
public function setParameter(string $id, mixed $value): static;
Sets a common parameters that is accessible in all view templates.
See also setParameter().
| public abstract Yiisoft\View\ViewInterface setParameters ( array $parameters ) | ||
| $parameters | array |
Parameters that are common for all view templates. |
public function setParameters(array $parameters): static;
Set the specified theme instance.
| public abstract Yiisoft\View\ViewInterface setTheme ( Yiisoft\View\Theme|null $theme ) | ||
| $theme | Yiisoft\View\Theme|null |
The theme instance or |
public function setTheme(?Theme $theme): static;
Returns a new instance with specified base path to the view directory.
| public abstract Yiisoft\View\ViewInterface withBasePath ( string|null $basePath ) | ||
| $basePath | string|null |
The base path to the view directory. |
public function withBasePath(string|null $basePath): static;
Returns a new instance with cleared state (blocks, parameters, etc.)
| public abstract Yiisoft\View\ViewInterface withClearedState ( ) |
public function withClearedState(): static;
Returns a new instance with the specified view context instance.
| public abstract Yiisoft\View\ViewInterface withContext ( Yiisoft\View\ViewContextInterface|null $context ) | ||
| $context | Yiisoft\View\ViewContextInterface|null |
The context under which the {@see \Yiisoft\View\render()} method is being invoked. |
public function withContext(ViewContextInterface|null $context): static;
Returns a new instance with the specified view context path.
| public abstract Yiisoft\View\ViewInterface withContextPath ( string $path ) | ||
| $path | string |
The context path under which the {@see \Yiisoft\View\render()} method is being invoked. |
public function withContextPath(string $path): static;
Set the specified locale code.
| public abstract Yiisoft\View\ViewInterface withLocale ( string $locale ) | ||
| $locale | string |
The locale code. |
public function withLocale(string $locale): static;
Returns a new instance with specified salt for the placeholder signature {@see getPlaceholderSignature()}.
| public abstract Yiisoft\View\ViewInterface withPlaceholderSalt ( string $salt ) | ||
| $salt | string |
The placeholder salt. |
public function withPlaceholderSalt(string $salt): static;
Returns a new instance with the specified renderers.
| public abstract Yiisoft\View\ViewInterface withRenderers ( array $renderers ) | ||
| $renderers | array |
A list of available renderers indexed by their corresponding supported file extensions.
If no renderer is available for the given view file, the view file will be treated as a normal PHP and rendered via {@see \Yiisoft\View\PhpTemplateRenderer}. |
public function withRenderers(array $renderers): static;
Returns a new instance with the specified source locale.
| public abstract Yiisoft\View\ViewInterface withSourceLocale ( string $locale ) | ||
| $locale | string |
The source locale. |
public function withSourceLocale(string $locale): static;
Set the specified theme instance immutable.
| public abstract Yiisoft\View\ViewInterface withTheme ( Yiisoft\View\Theme|null $theme ) | ||
| $theme | Yiisoft\View\Theme|null |
The theme instance or |
public function withTheme(?Theme $theme): static;
Signup or Login in order to comment.