Skip to content

Global Helpers

URLFor()

URLFor() — returns string

Available in: controller, model, mapper, migrator, migration, tabledefinition Category: Miscellaneous Functions

Creates an internal URL based on supplied arguments.

NameTypeRequiredDefaultDescription
routestringno—Name of a route that you have configured in config/routes.cfm.
controllerstringno—Name of the controller to include in the URL.
actionstringno—Name of the action to include in the URL.
keyanyno—Key(s) to include in the URL.
paramsstringno—Any additional parameters to be set in the query string (example: wheels=cool&x=y). Please note that Wheels uses the & and = characters to split the parameters and encode them properly for you. 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.
anchorstringno—Sets an anchor name to be appended to the path.
onlyPathbooleannotrueIf true, returns only the relative URL (no protocol, host name or port).
hoststringno—Set this to override the current host.
protocolstringno—Set this to override the current protocol.
portnumericno0Set this to override the current port number.
encodebooleannotrueEncode URL parameters using EncodeForURL(). Please note that this does not make the string safe for placement in HTML attributes, for that you need to wrap the result in EncodeForHtmlAttribute() or use linkTo(), startFormTag() etc instead.
$encodeForHtmlAttributebooleannofalse
$URLRewritingstringno[runtime expression]