Controller

Moduleejs.web
Definition class Controller
InheritanceController inherit Object
Specifiedejscript-1.1
StabilityPrototype.

Web framework controller.

Part of the Ejscript web MVC framework. Controller objects are not instantiated by users but are created internally by the web framework.


Properties

QualifiersPropertyTypeDescription
public absUrlStringStores application global data. The application array provides a means to store persistent information to be shared across all clients using an application. Objects and variables stored in the application array will live until either explicitly deleted or the web server exits. The application array does not persist over system reboots. The elements are User defined. NOTE: Not yet implemented.
public actionNameStringName of the action being run.
public appUrlStringRelative URL for the application. Does not include the URL scheme or host name portion.
public configObjectWeb application configuration. This is initialized from the config *..ecf files.
public controllerNameStringLower case controller name.
public flashObjectFlash messages to display on the next screen "inform" Informational / postitive feedback (note) "message" Neutral feedback (reminders, suggestions...) "warning" Negative feedback (Warnings and errors) "error" Negative errors (Warnings and errors).
public homeStringPhysical home directory of the application.
public hostHostHost object.
public paramsObjectForm parameters.
public requestRequestThe request object stores details of the incoming client's request.
public responseResponseThe response object stores details of the response going back to the client.
public sessionObjectStores session state information. The session array will be created automatically if SessionAutoCreate is defined or if a session is started via the useSession() or createSession() functions. Sessions are shared among requests that come from a single client. This may mean that multiple requests access the same session concurrently. Ejscript ensures that such accesses are serialized. The elements are user defined.

Controller Methods

QualifiersMethod
cache(enable: Boolean = true): Void
 Add a cache-control header to direct the browser to not cache the response.
Controller()
createSession(timeout: Number = 0): Void
 Enable session control.
destroySession(): Void
 Destroy a session.
discardOutput(): Void
 Discard all prior output.
doAction(act: String): Void
 Invoke the named action.
error(msg: String): Void
 Send an error notification to the user.
escapeHtml(s: String): String
 Transform a string to be safe for output into an HTML web page.
html(args: Array): String
 HTML encode the arguments.
inform(msg: String): Void
 Send a positive notification to the user.
initialize(isApp: Boolean, appDir: String, appUrl: String, session: Session, host: Host, request: Request, response: Response): Void
 Controller initialization.
keepAlive(on: Boolean): Void
 Control whether the HTTP connection is kept alive after this request.
loadView(path: String = null): Void
 Load a view.
makeUrl(action: String, id: String = null , options: Object = expression , query: Object = null): String
 Make a URL suitable for invoking actions.
action missing(): Void
 Missing action method.
redirect(action: String, id: String = null , options: Object = expression): Void
 Redirect to the given action.
redirectUrl(url: String, code: Number = 302): Void
 Redirect the client to a new URL.
render(args: Array): Void
 Render the raw arguments back to the client.
renderFile(filename: String): Void
 Render a file's contents.
renderRaw(args: Array): Void
 Render raw data.
renderView(viewName: String = null): Void
 Render a view template.
sendError(code: Number, msg: String): Void
 Send an error response back to the client.
setCookie(name: String, value: String, path: String = null , domain: String = null , lifetime: Number = 0 , secure: Boolean = false): Void
 Define a cookie header to include in the reponse.
setHeader(key: String, value: String, allowMultiple: Boolean = false): Void
 Of the format "keyword: value".
setHttpCode(code: Number): Void
 Set the HTTP response status code.
setMimeType(format: String): Void
 Set the response body mime type.
unescapeHtml(s: String): String
 Transform an escaped string into its original contents.
warn(msg: String): Void
 Send a warning message back to the client for display in the flash area.
write(args: Array): Void
 Write text to the client.
writeHtml(args: Array): Void
 Send text back to the client which must first be HTML escaped.

Method Detail

cache(enable: Boolean = true): Void

Add a cache-control header to direct the browser to not cache the response.

Parameters
enable: Boolean [default: true]

createSession(timeout: Number = 0): Void

Enable session control.

Description
This enables session state management for this request and other requests from the browser. If a session has not already been created, this call creates a session and sets the.
Parameters
timeout: Number Optional timeout for the session in seconds. If ommitted the default timeout is used. [default: 0]

destroySession(): Void

Destroy a session.

Description
This call destroys the session state store that is being used for the current client. If no session exists, this call has no effect.

discardOutput(): Void

Discard all prior output.


doAction(act: String): Void

Invoke the named action.

Description
Internal use only. Called from ejsWeb.c.
Parameters
act: String Action name to invoke.

error(msg: String): Void

Send an error notification to the user.

Description
This is just a convenience instead of setting flash["error"].
Parameters
msg: String Message to display.

escapeHtml(s: String): String

Transform a string to be safe for output into an HTML web page.

Description
It does this by changing the "&", ">", "<" and '"' characters into their ampersand HTML equivalents.
Parameters
s: String Input string.
Returns
A transformed HTML escaped string.

html(args: Array): String

HTML encode the arguments.

Parameters
args: Array Variable arguments that will be converted to safe html.
Returns
A string containing the encoded arguments catenated together.

inform(msg: String): Void

Send a positive notification to the user.

Description
This is just a convenience instead of setting flash["inform"].
Parameters
msg: String Message to display.

initialize(isApp: Boolean, appDir: String, appUrl: String, session: Session, host: Host, request: Request, response: Response): Void

Controller initialization.

Description
This is specially hand-crafted by the hosting web server so that it runs before the sub-classing constructors.
Parameters
isApp: Boolean True if the request if for an MVC application.
appDir: String Set to the top level directory containing the application.
appUrl: String URL that points to the application.
session: Session Session state object.
host: Host Host object.
request: Request Request object.
response: Response Response object.

keepAlive(on: Boolean): Void

Control whether the HTTP connection is kept alive after this request.


loadView(path: String = null): Void

Load a view.

Description
If path is not supplied, use the default view for the current action.
Parameters
path: String [default: null]

makeUrl(action: String, id: String = null , options: Object = expression , query: Object = null): String

Make a URL suitable for invoking actions.

Description
This routine will construct a URL Based on a supplied action name, model id and options that may contain an optional controller name. This is a convenience routine remove from applications the burden of building URLs that correctly use action and controller names.
Parameters
action: String The action name to invoke in the URL. If the name starts with "." or "/", it is assumed to be a controller name and it is used by itself.
id: String The model record ID to select via the URL. Defaults to null. [default: null ]
options: Object The options string. [default: expression ]
query: Object Query. [default: null]
Options
urlAn override url to use. All other args are ignored.
queryQuery string to append to the URL. Overridden by the query arg.
controllerThe name of the controller to use in the URL.
Returns
A string URL.

action missing(): Void

Missing action method.

Description
This method will be called if the requested action routine does not exist.

redirect(action: String, id: String = null , options: Object = expression): Void

Redirect to the given action.

Parameters
action: String Action to redirect to.
id: String Request ID. [default: null ]
options: Object Call options. [default: expression]
Options
idController.

redirectUrl(url: String, code: Number = 302): Void

Redirect the client to a new URL.

Description
This call redirects the client's browser to a new location specified by the.
Parameters
url: String Url to redirect the client to.
code: Number Optional HTTP redirection code. [default: 302]

render(args: Array): Void

Render the raw arguments back to the client.

Description
The args are converted to strings.

renderFile(filename: String): Void

Render a file's contents.


renderRaw(args: Array): Void

Render raw data.


renderView(viewName: String = null): Void

Render a view template.

Parameters
viewName: String [default: null]

sendError(code: Number, msg: String): Void

Send an error response back to the client.

Description
This calls discard the output.
Parameters
code: Number Http status code.
msg: String Message to display.

setCookie(name: String, value: String, path: String = null , domain: String = null , lifetime: Number = 0 , secure: Boolean = false): Void

Define a cookie header to include in the reponse.

Description
Path, domain and lifetime can be set to null for default values.
Parameters
name: String Cookie name.
value: String Cookie value.
path: String URI path to which the cookie applies. [default: null ]
domain: String Domain in which the cookie applies. Must have 2-3 dots. [default: null ]
lifetime: Number Duration for the cookie to persist in seconds. [default: 0 ]
secure: Boolean Set to true if the cookie only applies for SSL based connections. [default: false]

setHeader(key: String, value: String, allowMultiple: Boolean = false): Void

Of the format "keyword: value".

Description
If a header has already been defined and \a allowMultiple is false, the header will be overwritten. If \a allowMultiple is true, the new header will be appended to the response headers and the existing header will also be output. NOTE: case does not matter in the header keyword.
Parameters
key: String Header key string.
value: String Header value.
allowMultiple: Boolean If false, overwrite existing headers with the same keyword. If true, all headers are output. [default: false]

setHttpCode(code: Number): Void

Set the HTTP response status code.

Parameters
code: Number HTTP status code to define.

setMimeType(format: String): Void

Set the response body mime type.

Parameters
format: String Mime type for the response. For example "text/plain".

unescapeHtml(s: String): String

Transform an escaped string into its original contents.

Description
This reverses the transformation done by escapeHtml.
Parameters
s: String Input string.
Returns
A transformed string.

warn(msg: String): Void

Send a warning message back to the client for display in the flash area.

Description
This is just a convenience instead of setting flash["warn"].
Parameters
msg: String Message to display.

write(args: Array): Void

Write text to the client.

Description
This call writes the arguments back to the client's browser. The arguments are converted to strings before writing back to the client. Text written using write, will be buffered up to a configurable maximum. This allows text to be written prior to setting HTTP headers with setHeader.
Parameters
args: Array Text or objects to write to the client.

writeHtml(args: Array): Void

Send text back to the client which must first be HTML escaped.

Parameters
args: Array Objects to emit.