Response
There are three ways to finish a request: render a view, call $App->response(), or redirect with App::go().
Rendering HTML
The default for any user-facing route. The view layer wraps the rendered .phtml in the configured layout:
$App->view->render('about.phtml', [
'team' => $teamMembers,
]);
See Views & Templates for the full picture.
Sending JSON
The response object is callable. Pass a string, array, or object plus a content type:
$App->response(['ok' => true, 'id' => 42], 'json');
$App->response(['error' => 'Not found'], 'json', 404);
The first argument can also be a raw string. The second is the content type (html, json, xml, text, none). The third is the HTTP status code.
Status-code shortcut
Pass an int alone for a bare status response:
$App->response(404); // 404 Not Found
$App->response(204); // 204 No Content
Redirects
Use the static helper for an immediate Location redirect plus exit:
$App->go('/login');
$App->go('/users/'.$id);
The handler stops there — no further code runs.
Custom headers
Pass headers as the fourth argument:
$App->response($csv, 'text', 200, [
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="report.csv"',
]);
Cache hints
The Response constructor accepts a list of "preset" cache modes that map to common header bundles:
$App->response = new \True\Response(['cacheJson', 'cacheHTML']);
Once configured, JSON and HTML responses get the matching Cache-Control headers automatically.
Errors and notices
$App->error() queues a message that the layout's notice block renders for the user. Three levels are supported:
$App->error('Settings saved.', 'notice');
$App->error('Verify your email first.', 'warning');
$App->error('Could not save changes.', 'error');
Internally each call appends to one of three globals — $GLOBALS['errorUserNotice'], errorUserWarning, or errorUserError — which the layout reads when it renders the notice block.
Same-request only
Call $App->error() on its own when you want the message displayed on the page you're about to render. The notice block in your layout picks it up automatically:
if (!$report) {
$App->error('Report not found for that date range.', 'warning');
}
$App->view->render('reports.phtml', $vars);
Notices don't survive a redirect. Because the queue lives in $GLOBALS, it resets on the next request. Don't pair $App->error() with $App->go() expecting the message to show up on the destination page — it won't. To confirm something on a follow-up page, either:
- Redirect to a dedicated thank-you / confirmation URL (e.g.
/contact-thanks) whose template renders the success copy directly, or - Pass a flag in the query string (
$App->go('/settings?saved=1')) and let the destination controller call$App->error()based on it.