Responses

makeResponse
render
denyAccess
pageNotFound
internalError
forward
redirect

makeResponse

Creates a PSR-7 ResponseInterface populated with headers and body content.
Wraps the response body with Turbo headers if Turbo is enabled for the route.
@return ResponseInterface Generated HTTP response

makeResponse(): ResponseInterface

render

Renders a response based on the route format.

Supports 'html' (template rendering), 'json' (JSON response),
'file' (file download), or defaults to custom HTML response.

@param string|array $source Template path, JSON data, or file path or custom HTML string
@param array|null $parameters Optional parameters for template rendering or JSON response
@param array $headers Additional headers to merge
@param string|null $prodFailureMsg Optional production error message
@param array|null $partialRootPaths Optional override for partial template paths
@param array|null $layoutRootPaths Optional override for layout template paths
@return ResponseInterface Generated PSR-7 HTTP response

protected function render(
	string|array $source,
	?array $parameters = NULL,
	array $headers = [],
	?string $prodFailureMsg = NULL,
	?array $partialRootPaths = NULL,
	?array $layoutRootPaths = NULL
): ResponseInterface

The response type must be set with the Route attribute.

Reference the documentation about the attribute for more details.


Example:

Format 'html':

return $this->render('EXT:extension/Resources/Private/PageView/Pages/Demo/Template.html', ['variable1' => 1, 'variable2' => 'test'], partialRootPaths: ['EXT:extension/Resources/Private/PageView/Partials']);

Unset format:

return $this->render('<p>Chuck Norris was once bitten by a cobra snake and after 2 days of excruciating pain the snake died.</p>', []);

denyAccess

Returns a 403 Access Denied error response.
@param string|null $message Developer message
@param string|null $messageProd User-friendly production message
@return ResponseInterface Error response

denyAccess(?string $message = NULL, ?string $messageProd = NULL): ResponseInterface

pageNotFound

Returns a 404 Page Not Found error response.
@param string|null $message Developer message
@param string|null $messageProd User-friendly production message
@return ResponseInterface Error response

pageNotFound(?string $message = NULL, ?string $messageProd = NULL): ResponseInterface

internalError

Returns a 500 Internal Server Error response.
@param string|null $message Developer message
@param string|null $messageProd User-friendly production message
@return ResponseInterface Error response

internalError(?string $message = NULL, ?string $messageProd = NULL): ResponseInterface

forward

Forwards the request to another controller and method.

Prevents forwarding to self controller to avoid recursion.

@param string $controller Fully qualified controller class name
@param string $method Method name to call on the controller
@return ResponseInterface The response from the forwarded controller method, or error response if failure

forward(string $controller, string $method): ResponseInterface

Example:

return $this->forward(Namespace\Of\Controller\Controllername::class, 'methodToCall');

redirect

Sends an HTTP redirect response.

Adds a cache-control header for permanent redirects (301).
Generates minimal HTML body with meta refresh and link for redirect.

@param string $path URL to redirect to
@param int $status HTTP status code (default 302 Found)
@param array $headers Additional headers to merge
@param string $bodyMsg Optional HTML content for the response body
@return ResponseInterface Redirect response

redirect(string $path, int $status = 302, array $headers = [], string $bodyMsg = ''): ResponseInterface