Response - rbertram90/core GitHub Wiki

Summary

Documentation for src/Response.php

Contents

Public Methods

setVar

Add a variable accessible in the response template

void setVar(string $name, mixed $value)

writeTemplate

Output the site php template file from file path

void writeTemplate(string $templatePath)

// Pre-defined variables for template
string $scripts;     // HTML for script files to include in page
string $stylesheets; // HTML for stylesheets to include in page
string $output;      // HTML for output generated by controller
array $currentUser;  // Details for logged in user
array $messages;     // Nested array each message example: [text => 'message to output', type => 'error']

See: Session documentation for information on adding messages

write

Output a php content template file from file path

void write(string $templatePath)

setTitle

Set the page meta title

void write(string $title)

setDescription

Set the meta description for the page

void setDescription(string $description)

setBody

Manually set the raw response body output - useful for ajax requests that doen't require a template

void setBody(string $output)

writeBody

Print the current body to screen

void writeBody()

addScript

Add a file to be included as a javascript file import (relative to public directory)

void addScript(string $filePath)

addStylesheet

Add a file to be included as a css file import (relative to public directory)

void addStylesheet($filePath)

redirect

Redirect elsewhere with optional message

void redirect(string $location, [string $message = '' [, string $messageType = 'info']])

addHeader

Add a header to the response

void addHeader(string $name, string $value)