linkTo()
Description
Creates a link to another page in your application. Pass in the name of a route to use your configured routes or a controller/action/key combination.
Function Syntax
linkTo([ text, confirm, route, controller, action, key, params, anchor, onlyPath, host, protocol, port ])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
text |
string |
No | |
The text content of the link. |
confirm |
string |
No | |
Pass a message here to cause a JavaScript confirmation dialog box to pop up containing the message. |
route |
string |
No | |
Name of a route that you have configured in config/routes.cfm. |
controller |
string |
No | |
Name of the controller to include in the URL. |
action |
string |
No | |
Name of the action to include in the URL. |
key |
any |
No | |
Key(s) to include in the URL. |
params |
string |
No | |
Any additional params to be set in the query string. |
anchor |
string |
No | |
Sets an anchor name to be appended to the path. |
onlyPath |
boolean |
No | true |
If true, returns only the relative URL (no protocol, host name or port). |
host |
string |
No | |
Set this to override the current host. |
protocol |
string |
No | |
Set this to override the current protocol. |
port |
numeric |
No | 0 |
Set this to override the current port number. |
Examples
#linkTo(text="Log Out", controller="account", action="logout")#
-> <a href="/account/logout">Log Out</a>
<!--- if you're already in the "account" controller, Wheels will assume that's where you want the link to go. --->
#linkTo(text="Log Out", action="logout")#
-> <a href="/account/logout">Log Out</a>
#linkTo(text="View Post", controller="blog", action="post", key=99)#
-> <a href="/blog/post/99">View Post</a>
#linkTo(text="View Settings", action="settings", params="show=all&sort=asc")#
-> <a href="/account/settings?show=all&sort=asc">View Settings</a>
<!--- given that a userProfile route has been configured in config/routes.cfm --->
#linkTo(text="Joe's Profile", route="userProfile", userName="joe")#
-> <a href="/user/joe">Joe's Profile</a>
