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 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 addToParameter( string $id, mixed $value ): Yiisoft\View\ViewInterface | ||
| $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 clear( ): void |
public function clear(): void;
Returns a new instance with deep clone of the object, including state cloning.
| public abstract deepClone( ): Yiisoft\View\ViewInterface |
public function deepClone(): static;
Gets the base path to the view directory.
| public abstract getBasePath( ): string | ||
| return | string |
The base view path. |
|---|---|---|
public function getBasePath(): string;
Gets content of the block by ID.
| public abstract getBlock( string $id ): string | ||
| $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 getLocale( ): string | ||
| return | string |
The locale code. |
|---|---|---|
public function getLocale(): string;
Gets a common parameter value by ID.
| public abstract getParameter( string $id, mixed $default ): mixed | ||
| $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 getPlaceholderSignature( ): string | ||
| return | string |
The placeholder signature. |
|---|---|---|
public function getPlaceholderSignature(): string;
Gets the theme instance, or null if no theme has been set.
| public abstract getTheme( ): Yiisoft\View\Theme|null | ||
| return | Yiisoft\View\Theme|null |
The theme instance, or |
|---|---|---|
public function getTheme(): ?Theme;
Gets the view file currently being rendered.
| public abstract getViewFile( ): string|null | ||
| return | string|null |
The view file currently being rendered. |
|---|---|---|
public function getViewFile(): ?string;
Checks the existence of a content block by ID.
| public abstract hasBlock( string $id ): boolean | ||
| $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 hasParameter( string $id ): boolean | ||
| $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 localize( string $file, string|null $locale = null, string|null $sourceLocale = null ): string | ||
| $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 removeBlock( string $id ): Yiisoft\View\ViewInterface | ||
| $id | string |
The unique identifier of the block. |
public function removeBlock(string $id): static;
Removes a common parameter.
| public abstract removeParameter( string $id ): Yiisoft\View\ViewInterface | ||
| $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 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 Yiisoft\View\ViewContextInterface::getViewPath() of the context set via withContext(). If the context instance was not set withContext(), it will be looked for under the base path.
| public abstract render( string $view, array $parameters = [] ): string | ||
| $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 setBlock( string $id, string $content ): Yiisoft\View\ViewInterface | ||
| $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 setLocale( string $locale ): Yiisoft\View\ViewInterface | ||
| $locale | string |
The locale code. |
public function setLocale(string $locale): static;
Sets a common parameter that is accessible in all view templates.
| public abstract setParameter( string $id, mixed $value ): Yiisoft\View\ViewInterface | ||
| $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 setParameters( array $parameters ): Yiisoft\View\ViewInterface | ||
| $parameters | array |
Parameters that are common for all view templates. |
public function setParameters(array $parameters): static;
Set the specified theme instance.
| public abstract setTheme( Yiisoft\View\Theme|null $theme ): Yiisoft\View\ViewInterface | ||
| $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 withBasePath( string|null $basePath ): Yiisoft\View\ViewInterface | ||
| $basePath | string|null |
The base path to the view directory. |
public function withBasePath(?string $basePath): static;
Returns a new instance with cleared state (blocks, parameters, etc.)
| public abstract withClearedState( ): Yiisoft\View\ViewInterface |
public function withClearedState(): static;
Returns a new instance with the specified view context instance.
| public abstract withContext( Yiisoft\View\ViewContextInterface|null $context ): Yiisoft\View\ViewInterface | ||
| $context | Yiisoft\View\ViewContextInterface|null |
The context under which the render() method is being invoked. |
public function withContext(?ViewContextInterface $context): static;
Returns a new instance with the specified view context path.
| public abstract withContextPath( string $path ): Yiisoft\View\ViewInterface | ||
| $path | string |
The context path under which the render() method is being invoked. |
public function withContextPath(string $path): static;
Set the specified locale code.
| public abstract withLocale( string $locale ): Yiisoft\View\ViewInterface | ||
| $locale | string |
The locale code. |
public function withLocale(string $locale): static;
Returns a new instance with specified salt for the placeholder signature getPlaceholderSignature().
| public abstract withPlaceholderSalt( string $salt ): Yiisoft\View\ViewInterface | ||
| $salt | string |
The placeholder salt. |
public function withPlaceholderSalt(string $salt): static;
Returns a new instance with the specified renderers.
| public abstract withRenderers( array $renderers ): Yiisoft\View\ViewInterface | ||
| $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 Yiisoft\View\PhpTemplateRenderer. |
public function withRenderers(array $renderers): static;
Returns a new instance with the specified source locale.
| public abstract withSourceLocale( string $locale ): Yiisoft\View\ViewInterface | ||
| $locale | string |
The source locale. |
public function withSourceLocale(string $locale): static;
Set the specified theme instance immutable.
| public abstract withTheme( Yiisoft\View\Theme|null $theme ): Yiisoft\View\ViewInterface | ||
| $theme | Yiisoft\View\Theme|null |
The theme instance or |
public function withTheme(?Theme $theme): static;
Signup or Login in order to comment.