Controller
Module | ejs.web |
Namespace | "ejs.web" |
Definition | class Controller |
Inheritance | Controller ![]() |
Web framework controller.
Part of the Ejscript web MVC framework.
Properties
Qualifiers | Property | Type | Description |
---|---|---|---|
public | actionName | String | Name of the action being run. |
public | application | Object | Stores 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 | appUrl | String | Base URL for the application. Does not include the URL scheme or host name portion. |
public | config | Object | Web application configuration. This is initialized from the config *..ecf files. |
public | controllerName | String | Lower case controller name. |
public | flash | Object | Flash 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 | home | String | Physical home directory of the application. |
public | host | Host | Host object. |
public | originalActionName | String | |
public | params | Object | Form parameters. |
public | request | Request | The request object stores details of the incoming client's request. |
public | response | Response | The response object stores details of the response going back to the client. |
public | session | Object | Stores 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
Qualifiers | Method |
---|---|
afterFilter(fn, options: Object): Void | |
beforeFilter(fn, options: Object): Void | |
cache(enable: Boolean): Void | |
Add a cache-control header to direct the browser to not cache the response. | |
Controller() | |
createSession(timeout: Number): 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 | |
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): Void | |
Load a view. | |
makeUrl(action: String, id: String, options: Object): String | |
Make a URL suitable for invoking actions. | |
action | missing(): Void |
Missing action method. | |
redirect(action: String, id: String, options: Object): Void | |
Redirect to the given action Options: id controller. | |
redirectUrl(url: String, code: Number): 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): 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, domain: String, lifetime: Number, secure: Boolean): Void | |
Define a cookie header to include in the reponse. | |
setHeader(key: String, value: String, allowMultiple: Boolean): 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. | |
statusMessage(args: Array) | |
Send a status message to any registered status message view controls. | |
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. | |
wrapFilter(fn, options: Object): Void | |
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. | |
writeRaw(args: Array): Void |
Method Detail
Add a cache-control header to direct the browser to not cache the response.
- Parameters
enable: Boolean [default: true]
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.
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.
Discard all prior output.
Invoke the named action.
- Description
- Internal use only. Called from ejsWeb.c.
- Parameters
act: String Action name to invoke
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 encode the arguments.
- Parameters
args: Array Variable arguments that will be converted to safe html
- Returns
- A string containing the encoded arguments catenated together.
Send a positive notification to the user.
- Description
- This is just a convenience instead of setting flash["inform"].
- Parameters
msg: String Message to display
Controller initialization.
- Description
- This is specially hand-crafted by the hosting web server so that it runs before the sub-classing constructors.
Load a view.
- Description
- If path is not supplied, use the default view for the current action.
- Parameters
path: 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 "/", 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. options: Object The options string
Options
url: An — override url to use. All other args are ignored.
controller: The — name of the controller to use in the URL.
- Returns
- A string URL.
Missing action method.
- Description
- This method will be called if the requested action routine does not exist.
Render the raw arguments back to the client.
- Description
- The args are converted to strings.
Send an error response back to the client.
- Description
- This calls discard.
- Parameters
msg: String Message to display
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 domain: String Domain in which the cookie applies. Must have 2-3 dots. lifetime: Number Duration for the cookie to persist in seconds secure: Boolean Set to true if the cookie only applies for SSL based connections [default: false]
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
allowMultiple: Boolean If false, overwrite existing headers with the same keyword. If true, all headers are output. [default: false]
Set the HTTP response status code.
- Parameters
code: Number HTTP status code to define
Set the response body mime type.
- Parameters
format: String Mime type for the response. For example "text/plain".
Send a status message to any registered status message view controls.
Transform an escaped string into its original contents.
- Description
- This reverses the transformation done by $escapeHtml. It does this by changing ", >, < back into ", < and >.
- Parameters
s: String input string
- Returns
- A transformed string.
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 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
Send text back to the client which must first be HTML escaped.
- Parameters
args: Array Objects to emit