Global Helpers
controller()
Signature
Section titled “Signature”controller() — returns any
Available in: controller, model, migrator, migration, tabledefinition
Category: Miscellaneous Functions
Description
Section titled “Description”Creates and returns a controller object with your own custom name and params. Used primarily for testing purposes.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | yes | — | Name of the controller to create. |
params | struct | no | [runtime expression] | The params struct (combination of form and URL variables). |
Examples
Section titled “Examples”// 1. Create a controller object for testing (no params)
usersController = controller("users");
// 2. Create a controller object with simulated request params for testing
params = {controller = "users", action = "show", key = 1};
usersController = controller(name = "users", params = params);
// 3. Use with processAction to test an action end-to-end
params = {controller = "users", action = "index"};
usersController = controller(name = "users", params = params);
usersController.processAction();
body = usersController.response();