The Action Context uses a mechanism called addons to provide functionality that lives both on the server and client. Each addon provides additional functions through a namespacing object that is appended to the ActionContext object. The ActionContext object is available in each controller function, but controllers need to require addons before accessing addon methods. See the ActionContext Class for the addon classes.
The Action Context addons allow you to do the following:
Using the ActionContext object ac, you would call a {method} from an {addon} with the following syntax:
ac.{addon}.{method}
For example, to get all of the query string parameters, you would use the Params addon with the url method as seen here:
ac.params.url()
Prior to version 0.5.0, Mojito attached addons to the ActionContext object for every HTTP request and mojit instance. As a result, you were able to use any of the Action Context addons by default.
In Mojito versions 0.5.0 and later, you need to explicitly require an addon before you can use it. You require an addon by including an associated string in the requires array of your controller. For example, in the controller below, the Params addon is required by adding the string 'mojito-params-addon' to the requires array.
YUI.add('Foo', function(Y, NAME) {
Y.namespace('mojito.controllers')[NAME] = {
index: function(ac) {
var all_params = ac.params.all();
}
};
// Require the addon by adding the param name to the requires array
}, '0.0.1', {requires: ['mojito', 'mojito-params-addon']});
The list below shows what strings are used to require addons.
Note
To run older applications with Mojito v0.5.0 and later, you will need to modify your controllers so that the ActionContext addons that are being used are required. The most common addons are Config, Params, Url, and Assets.
The following code examples use the addons in parentheses:
Because customized addons are not part of the standard API, but an extension of the API, the instructions for creating addons can be found in Creating New Addons.