Documentation

Response extends RequestResponseHandler
in package

The Response class provides functions used by controllers to respond to requests

Table of Contents

$booter  : z_framework
__construct()  : mixed
Constructor that every request and response object should have
doCED()  : mixed
Executes a "Create Edit Delete"
error()  : mixed
Generates a generic error
formErrors()  : mixed
Sends an error array generated by validateForm() from Request. Exit
generateRest()  : mixed
Generates a Rest object
generateRestError()  : mixed
Generates a Rest error object
getBooterSettings()  : mixed
Gets a booter setting
getCookieDomainScope()  : string
getModel()  : z_model
Gets the database communication interface
getZControllers()  : string
Returns the ZControllers directory
getZRoot()  : string
Returns the framework root directory
getZViews()  : string
Returns the ZViews directory
insertDatabase()  : mixed
Inserts a set into the database with data from a form
insertOrUpdateDatabase()  : mixed
Inserts a set into the database with data from a form. Updates if the set already exists
log()  : mixed
Logs something
loginAs()  : mixed
Logs the current user in as someone else
logout()  : mixed
Logs the user out
render()  : mixed
Shows a document to the user
reroute()  : mixed
Reroutes to another action
rerouteUrl()  : mixed
Reroutes at the user's client
sendEmail()  : mixed
Sends an email to an address
sendEmailToUser()  : mixed
Sends an email to a user
setCookie()  : mixed
Sets a cookie just like the standard PHP function. (Pass-through) See: https://www.php.net/manual/en/function.setcookie.php
success()  : mixed
Sends a success message to the client. Exit
unsetCookie()  : mixed
Removes a cookie at the client
updateDatabase()  : mixed
Updates a database row with data from a user-filled form
upload()  : z_upload
Creates an upload object that handles the rest of the upload.
deleteOldLoginCookieDomainScope()  : void
Deletes the login token for the domain specified in `login_scope_allow_subdomains_delete_domainscope_name`.
getNewRest()  : mixed
Gets a new Rest object
uploadFromForm()  : mixed

Properties

Methods

doCED()

Executes a "Create Edit Delete"

public doCED(string $table, FormResult $validationResult[, array<string|int, mixed> $fix = [] ]) : mixed
Parameters
$table : string

The name of the affected table in the database

$validationResult : FormResult

The result of a validated CED

$fix : array<string|int, mixed> = []

Fixed values. For example, fix user ID not set by the client

Return values
mixed

error()

Generates a generic error

public error([string $message = "" ]) : mixed
Parameters
$message : string = ""

An error message

Return values
mixed

formErrors()

Sends an error array generated by validateForm() from Request. Exit

public formErrors(array<string|int, object> $errors) : mixed
Parameters
$errors : array<string|int, object>

The error array.

Return values
mixed

generateRest()

Generates a Rest object

public generateRest(array<string|int, mixed> $payload[, bool $die = true ]) : mixed
Parameters
$payload : array<string|int, mixed>

Data payload

$die : bool = true

Whether to exit after generating the Rest object

Return values
mixed

generateRestError()

Generates a Rest error object

public generateRestError(string $code, string $message) : mixed
Parameters
$code : string

Code

$message : string

Error message

Return values
mixed

getBooterSettings()

Gets a booter setting

public getBooterSettings([string $key = null ][, mixed $useDefault = true ][, mixed $default = null ]) : mixed
Parameters
$key : string = null

Key of the setting

$useDefault : mixed = true
$default : mixed = null
Return values
mixed

Value of the key

getCookieDomainScope()

public getCookieDomainScope() : string
Return values
string

getZControllers()

Returns the ZControllers directory

public getZControllers() : string
Return values
string

insertDatabase()

Inserts a set into the database with data from a form

public insertDatabase(string $table, FormResult $validationResult[, array<string|int, mixed> $fixed = [] ]) : mixed
Parameters
$table : string

Table name in the database

$validationResult : FormResult

Result of the validation

$fixed : array<string|int, mixed> = []

Some values to add to the database that were not in the FormResult

Return values
mixed

insertOrUpdateDatabase()

Inserts a set into the database with data from a form. Updates if the set already exists

public insertOrUpdateDatabase(string $table, string $pkField, string $pkType, string $pkValue, FormResult $validationResult[, array<string|int, mixed> $fixed = [] ]) : mixed
Parameters
$table : string

Table name in the database

$pkField : string

Name of the primary key field in the database

$pkType : string

Type of the primary key field ("s"/"i"...)

$pkValue : string

Value of the primary key in the row to change

$validationResult : FormResult

Result of the validation

$fixed : array<string|int, mixed> = []

Fixed values to add, which are not coming from the form

Return values
mixed

log()

Logs something

public log(string $categoryName, string $text, int $value) : mixed
Parameters
$categoryName : string

Name of the log category in the database

$text : string

Log text

$value : int

Log value

Return values
mixed

loginAs()

Logs the current user in as someone else

public loginAs(int $userId[, int $user_exec = null ]) : mixed
Parameters
$userId : int

ID of the user to sudo into

$user_exec : int = null

ID of the executing user

Return values
mixed

logout()

Logs the user out

public logout() : mixed
Return values
mixed

render()

Shows a document to the user

public render(string $document[, array<string|int, mixed> $opt = [] ][, string|array<string|int, mixed> $options = [] ]) : mixed
Parameters
$document : string

Path to the view

$opt : array<string|int, mixed> = []

Associative array with values to replace in the view

$options : string|array<string|int, mixed> = []

Rendering options, e.g., or a string for layout

Return values
mixed

reroute()

Reroutes to another action

public reroute([array<string|int, string> $path = [] ][, bool $alias = false ][, bool $final = false ]) : mixed
Parameters
$path : array<string|int, string> = []

Path to where to reroute to

$alias : bool = false

True if this reroute acts as an alias

$final : bool = false

Executes and exits if set to true

Return values
mixed

rerouteUrl()

Reroutes at the user's client

public rerouteUrl([string $url = "" ][, string $root = null ]) : mixed
Parameters
$url : string = ""

The URL to reroute to

$root : string = null

The root URL

Return values
mixed

sendEmail()

Sends an email to an address

public sendEmail(string $to, string $subject, string $document[, string $lang = "en" ][, array<string|int, mixed> $options = [] ][, string $layout = "email" ][, array<string|int, string> $attachments = [] ]) : mixed
Parameters
$to : string

Mail address

$subject : string

Subject of the mail

$document : string

View

$lang : string = "en"

Language identifier ("EN", "DE_Formal"...)

$options : array<string|int, mixed> = []

Options to use in the view

$layout : string = "email"

Layout

$attachments : array<string|int, string> = []

Contents of each attachment, not their path. Array keys can be used to set the filename i.e. $filename => $content

Return values
mixed

sendEmailToUser()

Sends an email to a user

public sendEmailToUser(int $userId, string $subject, string $document[, array<string|int, mixed> $options = [] ][, string $layout = "mail" ]) : mixed
Parameters
$userId : int

ID of the target user

$subject : string

Subject of the mail

$document : string

View of the mail

$options : array<string|int, mixed> = []

Options for use in the view

$layout : string = "mail"

Layout to use

Return values
mixed

setCookie()

Sets a cookie just like the standard PHP function. (Pass-through) See: https://www.php.net/manual/en/function.setcookie.php

public setCookie() : mixed
Return values
mixed

success()

Sends a success message to the client. Exit

public success([array<string|int, mixed> $payload = [] ]) : mixed
Parameters
$payload : array<string|int, mixed> = []

An optional payload that will be added to the result

Return values
mixed

unsetCookie()

Removes a cookie at the client

public unsetCookie(string $name[, string $path = "/" ][, string $domainScope = "" ]) : mixed
Parameters
$name : string

Name of the cookie

$path : string = "/"

Path on the server

$domainScope : string = ""

The domain scope of the cookie

Return values
mixed

updateDatabase()

Updates a database row with data from a user-filled form

public updateDatabase(string $table, string $pkField, string $pkType, string $pkValue, FormResult $validationResult[, array<string|int, mixed> $fixed = [] ]) : mixed
Parameters
$table : string

Table name in the database

$pkField : string

Name of the primary key field in the database

$pkType : string

Type of the primary key field ("s"/"i"...)

$pkValue : string

Value of the primary key in the row to change

$validationResult : FormResult

Result of the validation

$fixed : array<string|int, mixed> = []
Return values
mixed

upload()

Creates an upload object that handles the rest of the upload.

public upload() : z_upload
Return values
z_upload

A new instance of the z_upload class

deleteOldLoginCookieDomainScope()

Deletes the login token for the domain specified in `login_scope_allow_subdomains_delete_domainscope_name`.

private deleteOldLoginCookieDomainScope() : void

Helpful when login_scope_allow_subdomains is altered after users already logged in.

Return values
void

getNewRest()

Gets a new Rest object

private getNewRest(array<string|int, mixed> $payload) : mixed
Parameters
$payload : array<string|int, mixed>

Data payload

Return values
mixed

Search results