Controller
Module | ejs.web |
Definition | class Controller |
Inheritance | Controller ![]() |
Specified | ejscript-1.1 |
Stability | Prototype. |
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
Qualifiers | Property | Type | Description |
---|---|---|---|
public | absUrl | String | 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 | actionName | String | Name of the action being run. |
public | appUrl | String | Relative 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 | 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 |
---|---|
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
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. [default: 0]
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.
Send an error notification to the user.
- Description
- This is just a convenience instead of setting flash["error"].
- Parameters
msg: String Message to display.
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.
- 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.
Load a view.
- Description
- If path is not supplied, use the default view for the current action.
- Parameters
path: String [default: null]
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
url An override url to use. All other args are ignored. query Query string to append to the URL. Overridden by the query arg. 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.
Render a view template.
- Parameters
viewName: String [default: null]
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]
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.
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".
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.
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.