final class View (View source)

Renders PHP templates while keeping layout state and request helpers on one isolated view instance.

Methods

__construct(string $basePath = 'app/views', ViewResourceRegistry|null $resources = null)

Creates an unbound view prototype for the configured template root.

void

Resets request bindings, temporary data, and in-progress rendering state on every clone.

void
forRequest(ViewHelpers $helpers, RequestViewHelpers $requestHelpers, array $shared = [])

Creates an isolated request-local clone with explicit helpers and request-scoped template data.

void
share(string $key, mixed $value)

Shares a value with this view and all clones created from it.

void
void
shareOnce(string $key, mixed $value)

Shares a value only until the current or next top-level render finishes.

void
void
shares(array $data)

Shares multiple values with this view and all clones created from it.

void
string
render(string $view, array $data = [])

Renders a view and its optional layout using one isolated render state.

string
string
partial(string $view, array $data = [])

Renders a nested view with the current request helpers and shared data.

string
string
template(string $layoutView, string $contentView, array $data = [])

Renders a content view inside a layout using one request and render context.

string
void
extend(string $layoutView)

Selects the layout rendered after the current top-level view completes.

void
string

Returns the rendered child content while a layout is being rendered.

string
void
start(string $name)

Starts capturing a named layout section.

void
void
end()

Finishes the most recently started section and stores its captured content.

void
string
section(string $name, string $default = '')

Returns a captured section or the caller-provided default.

string
string
lang(string $key, array $replacements = [], string|null $locale = null)

Translates one message with scalar replacements in the current request context.

string
array
langGroup(string $group, string|null $locale = null)

Returns one complete translation group for a locale in the current request context.

array
array
langAll(string|null $locale = null)

Returns every translation group for a locale in the current request context.

array
string
currentLocale(string $default = 'en')

Returns the active runtime locale or a configured or caller-provided fallback.

string
string

Returns the active request path without its query string.

string
string

Returns the active request query string without a leading question mark.

string
string
currentUrl(bool $withQuery = true)

Returns the active request path with an optional query string.

string
string
currentFullUrl(bool $withQuery = true)

Returns the canonical absolute request URL with an optional query string.

string
bool
isUrlActive(string $url, bool $startsWith = false)

Compares a URL against the active request path using exact or prefix matching.

bool
bool
isRouteActive(string $route, array $params = [], bool $startsWith = false)

Generates a route URL and compares it with the active request path.

bool
string
url(string $route, array $params = [])

Generates a URL for a named route.

string
string
localizedUrl(string $route, array $params = [], string|null $locale = null)

Generates a locale-aware URL for a named route.

string
string
asset(string $path)

Returns a root-relative asset URL without requiring a canonical application origin.

string
string
image(ImageReference|null $reference, ImageViewOptions|null $options = null)

Renders an image reference through the configured image integration.

string
string
csrfField(string $name = 'default')

Renders an escaped hidden field containing a token from the current request session.

string
string
csrfToken(string $name = 'default')

Returns a named CSRF token from the current request session.

string

Details

__construct

__construct(string $basePath = 'app/views', ViewResourceRegistry|null $resources = null)

Creates an unbound view prototype for the configured template root.

Parameters

string $basePath
ViewResourceRegistry|null $resources

__clone

void __clone()

Resets request bindings, temporary data, and in-progress rendering state on every clone.

Return Value

void

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.

Parameters

ViewHelpers $helpers
RequestViewHelpers $requestHelpers
array $shared

Return Value

View

share

void share(string $key, mixed $value)

Shares a value with this view and all clones created from it.

Parameters

string $key
mixed $value

Return Value

void

shareOnce

void shareOnce(string $key, mixed $value)

Shares a value only until the current or next top-level render finishes.

Parameters

string $key
mixed $value

Return Value

void

shares

void shares(array $data)

Shares multiple values with this view and all clones created from it.

Parameters

array $data

Return Value

void

render

string render(string $view, array $data = [])

Renders a view and its optional layout using one isolated render state.

Parameters

string $view
array $data

Return Value

string

partial

string partial(string $view, array $data = [])

Renders a nested view with the current request helpers and shared data.

Parameters

string $view
array $data

Return Value

string

template

string template(string $layoutView, string $contentView, array $data = [])

Renders a content view inside a layout using one request and render context.

Parameters

string $layoutView
string $contentView
array $data

Return Value

string

extend

void extend(string $layoutView)

Selects the layout rendered after the current top-level view completes.

Parameters

string $layoutView

Return Value

void

content

string content()

Returns the rendered child content while a layout is being rendered.

Return Value

string

start

void start(string $name)

Starts capturing a named layout section.

Parameters

string $name

Return Value

void

end

void end()

Finishes the most recently started section and stores its captured content.

Return Value

void

section

string section(string $name, string $default = '')

Returns a captured section or the caller-provided default.

Parameters

string $name
string $default

Return Value

string

lang

string lang(string $key, array $replacements = [], string|null $locale = null)

Translates one message with scalar replacements in the current request context.

Parameters

string $key
array $replacements
string|null $locale

Return Value

string

langGroup

array langGroup(string $group, string|null $locale = null)

Returns one complete translation group for a locale in the current request context.

Parameters

string $group
string|null $locale

Return Value

array

langAll

array langAll(string|null $locale = null)

Returns every translation group for a locale in the current request context.

Parameters

string|null $locale

Return Value

array

currentLocale

string currentLocale(string $default = 'en')

Returns the active runtime locale or a configured or caller-provided fallback.

Parameters

string $default

Return Value

string

currentPath

string currentPath()

Returns the active request path without its query string.

Return Value

string

currentQuery

string currentQuery()

Returns the active request query string without a leading question mark.

Return Value

string

currentUrl

string currentUrl(bool $withQuery = true)

Returns the active request path with an optional query string.

Parameters

bool $withQuery

Return Value

string

currentFullUrl

string currentFullUrl(bool $withQuery = true)

Returns the canonical absolute request URL with an optional query string.

Parameters

bool $withQuery

Return Value

string

isUrlActive

bool isUrlActive(string $url, bool $startsWith = false)

Compares a URL against the active request path using exact or prefix matching.

Parameters

string $url
bool $startsWith

Return Value

bool

isRouteActive

bool isRouteActive(string $route, array $params = [], bool $startsWith = false)

Generates a route URL and compares it with the active request path.

Parameters

string $route
array $params
bool $startsWith

Return Value

bool

url

string url(string $route, array $params = [])

Generates a URL for a named route.

Parameters

string $route
array $params

Return Value

string

localizedUrl

string localizedUrl(string $route, array $params = [], string|null $locale = null)

Generates a locale-aware URL for a named route.

Parameters

string $route
array $params
string|null $locale

Return Value

string

asset

string asset(string $path)

Returns a root-relative asset URL without requiring a canonical application origin.

Parameters

string $path

Return Value

string

image

string image(ImageReference|null $reference, ImageViewOptions|null $options = null)

Renders an image reference through the configured image integration.

Parameters

ImageReference|null $reference
ImageViewOptions|null $options

Return Value

string

Exceptions

LogicException

csrfField

string csrfField(string $name = 'default')

Renders an escaped hidden field containing a token from the current request session.

Parameters

string $name

Return Value

string

csrfToken

string csrfToken(string $name = 'default')

Returns a named CSRF token from the current request session.

Parameters

string $name

Return Value

string