Download Plugin (zip)

Stats

Version

0.2

Wheels Compatibility

1.0

Downloads

95

Last Updated

December 27, 2009

About Plugins

Plugins allow you to extend or modify default Wheels application behavior. To use, you just drop the zip file into your plugins directory and reload your application.

Read Using and Creating Plugins for more information.

Provides

The Provides Plugin lets you manage the data format returned by your Wheels controller.

Author

James Gibson

Project Home

http://iamjamesgibson.com/code

Description

Currently, three format options are supported -- HTML, XML, or JSON. Unless one of the other formats is specified, HTML is returned as the default.

So, how does the plugin know which format to return? Two options are available:

  • Examining a URL or FORM parameter named "format." For example, ?format=xml will return XML and ?format=json will return JSON.
  • Examining the HTTP header. The plugin looks at cgi.http_accept in the request header and returns XML (text/xml) or JSON (text/json) as appropriate.

Basic Usage

Add a call to the provides() function in the init() method of your controller to specify which formats your controller can return.

<cfset provides(formats="html,xml,json")>

Add a call to the renderWith() function at the bottom of any action that you want to return XML or JSON.

<cfset renderWith(yourModelObject)>

Methods

  • provides(formats="html,xml,json") - use this method in your controller init() and pass in the types your would like to controller to respond to.
  • onlyProvides(formats="html") - use this method in an action to say that it only provide particular formats. A good example would be for a new() action where a form is displayed. In this case, there is no data to show, so the action should only provide html.
  • renderWith(object=dataToDisplay) - Call renderWith() at the bottom of every action that you want to respond to different formats. The argument object should be passed the data to transform to XML or JSON if that format is requested. Please note that you can also pass display any arguments for renderPage() and they will be passed through appropriately.

The renderWith() method should be able to take lists (strings), arrays, structures, arrays of structures, queries and arrays of wheels model objects and properly display them as XML or JSON. If the request type is set to HTML, the data is ignored and renderPage() is called.

Uninstallation

To uninstall this plugin simply delete the /plugins/Provides-0.2.zip file.

Credits

This plugin was created by James Gibson and Clarke Bishop.

Change Log

Version 0.2—November 24, 2009 Download

  • None recorded.
  • Wheels compatibility: 1.0.

Version 0.1—October 3, 2009 Download

  • Initial release.
  • Wheels compatibility: 0.9.4.