Showing content to the user.
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
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.
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.
Normally when you call any of the rendering functions, the result is stored inside an internal Wheels variable. This value is then outputted 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
returnAsargument comes in handy. It's available on both renderView() and renderPartial(). Setting
stringwill return the result to you instead of placing it in the internal Wheels variable.
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
xis 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.