Skip to content

Miscellaneous

urlFor()

urlFor() — returns any

Creates an internal URL based on supplied arguments.

NameTypeRequiredDefaultDescription
routestringyesName of a route that you have configured in config/routes.cfm.
controllerstringyesName of the controller to include in the URL.
actionstringyesName of the action to include in the URL.
keyanyyesKey(s) to include in the URL.
paramsstringyesAny additional parameters to be set in the query string (example: wheels=cool&x=y). Please note that CFWheels uses the & and = characters to split the parameters and encode them properly for you (using URLEncodedFormat() internally). However, if you need to pass in & or = as part of the value, then you need to encode them (and only them), example: a=cats%26dogs%3Dtrouble!&b=1.
anchorstringyesSets an anchor name to be appended to the path.
onlyPathbooleanyestrueIf true, returns only the relative URL (no protocol, host name or port).
hoststringyesSet this to override the current host.
protocolstringyesSet this to override the current protocol.
portnumericyes0Set this to override the current port number.
urlFor([ route, controller, action, key, params, anchor, onlyPath, host, protocol, port ]) <!--- Create the URL for the `logOut` action on the `account` controller, typically resulting in `/account/log-out` --->
#urlFor(controller="account", action="logOut")#

<!--- Create a URL with an anchor set on it --->
#urlFor(action="comments", anchor="comment10")#

<!--- Create a URL based on a route called `products`, which expects params for `categorySlug` and `productSlug` --->
#urlFor(route="product", categorySlug="accessories", productSlug="battery-charger")#