CLI Overview
Quick Start Guide
wheels info
wheels reload
wheels deps
wheels destroy
wheels watch
wheels generate app
wheels generate app-wizard
wheels generate controller
wheels generate model
wheels generate view
wheels generate property
wheels generate route
wheels generate resource
wheels generate api-resource
wheels generate frontend
wheels generate test
wheels generate snippets
wheels scaffold
wheels db create
wheels db drop
wheels db setup
wheels db reset
wheels db status
wheels db version
wheels db rollback
wheels db seed
wheels db dump
wheels db restore
wheels db shell
wheels db schema
wheels dbmigrate info
wheels dbmigrate latest
wheels dbmigrate up
wheels dbmigrate down
wheels dbmigrate reset
wheels dbmigrate exec
wheels dbmigrate create blank
wheels dbmigrate create table
wheels dbmigrate create column
wheels dbmigrate remove table
wheels test
wheels test run
wheels test coverage
wheels test debug
wheels config list
wheels config set
wheels config env
wheels env
wheels env setup
wheels env list
wheels env switch
wheels environment
wheels console
wheels runner
wheels server
wheels server start
wheels server stop
wheels server restart
wheels server status
wheels server log
wheels server open
wheels plugins
wheels plugins list
wheels plugins install
wheels plugins remove
wheels analyze
wheels analyze code
wheels analyze performance
wheels analyze security
wheels security
wheels security scan
wheels optimize
wheels optimize performance
wheels docs
wheels docs generate
wheels docs serve
wheels ci init
wheels docker init
wheels docker deploy
wheels deploy
wheels deploy audit
wheels deploy exec
wheels deploy hooks
wheels deploy init
wheels deploy lock
wheels deploy logs
wheels deploy proxy
wheels deploy push
wheels deploy rollback
wheels deploy secrets
wheels deploy setup
wheels deploy status
wheels deploy stop
Configuration Management
Creating Commands
Service Architecture
Migrations Guide
Testing Guide
Object Relational Mapping
Creating Records
Reading Records
Updating Records
Deleting Records
Column Statistics
Dynamic Finders
Getting Paginated Data
Associations
Nested Properties
Object Validation
Object Callbacks
Calculated Properties
Transactions
Dirty Records
Soft Delete
Automatic Time Stamps
Using Multiple Data Sources
description: Showing content to the user.
Rendering Content
A big part of a controller's task is to respond to the user. In Wheels you can
respond to the user in three different ways:
- Displaying content
- Redirecting to another URL
- Sending a file
You can only respond once per request. If you do not explicitly call any of the
response functions ( renderView(), sendFile() etc) then Wheels will
assume that you want to show the view for the current controller and action and
do it for you.
This chapter covers the first method listed above—displaying content. The
chapters about Redirecting Users and Sending Files cover the other two
response methods.
Rendering a Page
This is the most common way of responding to the user. It's done with the
renderView() function, but most often you probably won't call it
yourself and instead let Wheels do it for you.
Sometimes you will want to call it though and specify to show a view page for a
controller/action other than the current one. One common technique for handling
a form submission, for example, is to show the view page for the
controller/action that contains the form (as opposed to the one that just
handles the form submission and redirects the user afterwards). When doing this,
it's very important to keep in mind that renderView() will
not run the code for the controller's action—all it does is process the view
page for it.
You can also call renderView() explicitly if you wish to cache the response
or use a different layout than the default one.
If the controller
and action
arguments do not give you enough flexibility,
you can use the template
argument that is available for renderView().
Refer to the Pages chapter for more details about rendering content. More
specifically, that chapter describes where to place those files and what goes in
them.
Rendering a Partial
This is done with the renderPartial() function. It's most often used with
AJAX requests that are meant to update only parts of a page.
Rendering Nothing at All
Sometimes you don't need to return anything at all to the browser. Perhaps
you've made an AJAX request that does not require a response or executed a
scheduled task that no end user sees the results of. In these cases you can use
the renderNothing() function to tell Wheels to just render an empty page to
the browser.
Rendering Text
This is done with the renderText() function. It just returns the text you
specify. In reality it is rarely used but could be useful as a response to AJAX
requests sometimes.
Rendering to a Variable
Normally when you call any of the rendering functions, the result is stored
inside an internal Wheels variable. This value is then output to the browser
at the end of the request.
Sometimes you may want to do some additional processing on the rendering result
before outputting it though. This is where the returnAs
argument comes in
handy. It's available on both renderView() and renderPartial().
Setting returnAs
to string
will return the result to you instead of placing
it in the internal Wheels variable.
Caching the Response
Two of the functions listed above are capable of caching the content for you;
renderView() and renderPartial(). Just pass in cache=true
(to use
the default cache time set in /config/settings.cfm
) or cache=x
where x
is
the number of minutes you want to cache the content for. Keep in mind that this
caching respects the global setting set for it in your configuration files so
normally no pages will be cached when in Design or Development mode.
We cover caching in greater detail in the Caching chapter.
Using a Layout
The renderView() function accepts an argument named layout
. Using this
you can wrap your content with common header/footer style code. This is such an
important concept though so we'll cover all the details of it in the chapter
called Using Layouts.