Skip to content

Global Helpers

controller()

controller() — returns any

Available in: controller, model, migrator, migration, tabledefinition Category: Miscellaneous Functions

Creates and returns a controller object with your own custom name and params. Used primarily for testing purposes.

NameTypeRequiredDefaultDescription
namestringyes—Name of the controller to create.
paramsstructno[runtime expression]The params struct (combination of form and URL variables).
// 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();