Say.cfc
in the controllers
directory and add the
code below to the file.Controller
component, it inherits quite a bit of powerful
functionality and is now tied into our CFWheels application.http://127.0.0.1:60000/say
.
You may need to enter a different URL, depending on how your web server is
configured. In my case, I'm using commandbox.index
. So in our example, CFWheels tried to find
the index
action within the say
controller, and it threw an error because it
couldn't find its view page.hello
. Change your say
controller so it looks like the
code block below:hello
.hello
action, we simply add /hello
to the end of the previous URL that we
used to call our say
controller:http://127.0.0.1:60000/say/hello
hello
action to it, we haven't created the view.say/hello
action and couldn't find one.views
directory in the root of your CFWheels installation. There will
be a few directories in there already. For now, we need to create a new
directory in the views
directory called say
. This is the same name as the
controller that we created above.say
directory, create a file called hello.cfm
. In the
hello.cfm
file, add the following line of code:hello.cfm
file, and let's call our say/hello
action once again.
You have your first working CFWheels page if your browser looks like Figure 3
below.hello
action and add a second
action to the application. We'll then use some CFWheels code to tie the 2
actions together. Let's get get to it!say/hello
action. Modify your say
controller so it looks like the code block
below:time
and setting its value
to the current server time using the basic ColdFusion Now()
function. When we
do this, the variable becomes immediately available to our view code.say/hello.cfm
view file so that it looks like the
code block bellow. When we do this, the value will be displayed in the browser.say/hello
action again in your browser. Your browser should look
like Figure 4 below.time
variable in the say/hello
controller action and display that
variable in our say/hello.cfm
view file.say
controller. If you feel adventurous, go ahead and add
a goodbye
action to the say
controller on your own, then create a
goodbye.cfm
view file that displays a "Goodbye" message to the user. If you're
not feeling that adventurous, we'll quickly go step by step.say
controller file so that it looks like the code block
below.views/say
directory and create a goodbye.cfm
page.goodbye.cfm
page and save it.say/goodbye
action using the following URL:http://127.0.0.1:60000/say/goodbye
say/hello.cfm
view file. We are going to add a line of code to the
end of this file so our say/hello.cfm
view file looks like the code block
below:text
, is the text
that will be displayed in the hyperlink. The second parameter, action
, defines the action to point the link to. By using this built-in function, your application's main URL may change, and even controllers and actions may get shifted around, but you won't suffer from the dreaded dead link. CFWheels will
always create a valid link for you as long as you configure it correctly when you make infrastructure changes to your application.say/hello.cfm
view file, save your file and call the say/hello
action from
your browser. Your browser should look like Figure 6 below.say/goodbye
action to the link.say/goodbye.cfm
view page.say/goodbye.cfm
view page and modify it so it looks like the code
block below.say/goodbye
action in your browser, your browser should
look like Figure 7 below.