Page Controller 1.5 Documentation: Defaulting, Requiring, Redirecting

Page Controller Information

Blog Entries

Check Out AFF

Defaulting, Requiring, Redirecting

Sometimes you need to set a default for a variable or require the presence of a variable on a page. Typically, cfparam would be used for this but the behaviour of cfparam can limit its usefulness.

Defaulting

<cfset default("URL.section","numeric",0)>

The default method set a variable to the given value if it is not a valid value. So, if the variable either is not set or is set to a value not of the type specified, the default function will set it to the default value. This differs from cfparam where an exception will be thrown if the variable is available but of the wrong type. With the default function, no exception will be thrown. Instead the default value will be used.

The argument for the default function are as follows:

Requiring

<cfset require("URL.id","numeric","/index.cfm")>

The require method ensures that a variable exists and is valid. If the variable does not exist with a valid value, then the browser is sent to the URL indicated.

The argument for the default function are as follows:

Redirecting

To manually redirect the browser to a new location, simply call the "go" function"

<cfset go("/index.cfm")>