View
final class View (View source)
Renders PHP templates while keeping layout state and request helpers on one isolated view instance.
Methods
Creates an unbound view prototype for the configured template root.
Resets request bindings, temporary data, and in-progress rendering state on every clone.
Creates an isolated request-local clone with explicit helpers and request-scoped template data.
Shares a value with this view and all clones created from it.
Shares a value only until the current or next top-level render finishes.
Shares multiple values with this view and all clones created from it.
Renders a view and its optional layout using one isolated render state.
Renders a nested view with the current request helpers and shared data.
Renders a content view inside a layout using one request and render context.
Selects the layout rendered after the current top-level view completes.
Returns the rendered child content while a layout is being rendered.
Starts capturing a named layout section.
Finishes the most recently started section and stores its captured content.
Returns a captured section or the caller-provided default.
Translates one message with scalar replacements in the current request context.
Returns one complete translation group for a locale in the current request context.
Returns every translation group for a locale in the current request context.
Returns the active runtime locale or a configured or caller-provided fallback.
Returns the active request path without its query string.
Returns the active request query string without a leading question mark.
Returns the active request path with an optional query string.
Returns the canonical absolute request URL with an optional query string.
Compares a URL against the active request path using exact or prefix matching.
Generates a route URL and compares it with the active request path.
Generates a URL for a named route.
Generates a locale-aware URL for a named route.
Returns a root-relative asset URL without requiring a canonical application origin.
Renders an image reference through the configured image integration.
Renders an escaped hidden field containing a token from the current request session.
Returns a named CSRF token from the current request session.
Details
__construct
__construct(string $basePath = 'app/views', ViewResourceRegistry|null $resources = null)
Creates an unbound view prototype for the configured template root.
__clone
void
__clone()
Resets request bindings, temporary data, and in-progress rendering state on every clone.
forRequest
View
forRequest(ViewHelpers $helpers, RequestViewHelpers $requestHelpers, array $shared = [])
| internal | The framework renderer lifecycle owns request binding. |
Creates an isolated request-local clone with explicit helpers and request-scoped template data.
share
void
share(string $key, mixed $value)
Shares a value with this view and all clones created from it.
shareOnce
void
shareOnce(string $key, mixed $value)
Shares a value only until the current or next top-level render finishes.
shares
void
shares(array $data)
Shares multiple values with this view and all clones created from it.
render
string
render(string $view, array $data = [])
Renders a view and its optional layout using one isolated render state.
partial
string
partial(string $view, array $data = [])
Renders a nested view with the current request helpers and shared data.
template
string
template(string $layoutView, string $contentView, array $data = [])
Renders a content view inside a layout using one request and render context.
extend
void
extend(string $layoutView)
Selects the layout rendered after the current top-level view completes.
content
string
content()
Returns the rendered child content while a layout is being rendered.
start
void
start(string $name)
Starts capturing a named layout section.
end
void
end()
Finishes the most recently started section and stores its captured content.
section
string
section(string $name, string $default = '')
Returns a captured section or the caller-provided default.
lang
string
lang(string $key, array $replacements = [], string|null $locale = null)
Translates one message with scalar replacements in the current request context.
langGroup
array
langGroup(string $group, string|null $locale = null)
Returns one complete translation group for a locale in the current request context.
langAll
array
langAll(string|null $locale = null)
Returns every translation group for a locale in the current request context.
currentLocale
string
currentLocale(string $default = 'en')
Returns the active runtime locale or a configured or caller-provided fallback.
currentPath
string
currentPath()
Returns the active request path without its query string.
currentQuery
string
currentQuery()
Returns the active request query string without a leading question mark.
currentUrl
string
currentUrl(bool $withQuery = true)
Returns the active request path with an optional query string.
currentFullUrl
string
currentFullUrl(bool $withQuery = true)
Returns the canonical absolute request URL with an optional query string.
isUrlActive
bool
isUrlActive(string $url, bool $startsWith = false)
Compares a URL against the active request path using exact or prefix matching.
isRouteActive
bool
isRouteActive(string $route, array $params = [], bool $startsWith = false)
Generates a route URL and compares it with the active request path.
url
string
url(string $route, array $params = [])
Generates a URL for a named route.
localizedUrl
string
localizedUrl(string $route, array $params = [], string|null $locale = null)
Generates a locale-aware URL for a named route.
asset
string
asset(string $path)
Returns a root-relative asset URL without requiring a canonical application origin.
image
string
image(ImageReference|null $reference, ImageViewOptions|null $options = null)
Renders an image reference through the configured image integration.
csrfField
string
csrfField(string $name = 'default')
Renders an escaped hidden field containing a token from the current request session.
csrfToken
string
csrfToken(string $name = 'default')
Returns a named CSRF token from the current request session.