Controller
processRequest()
Signature
Section titled “Signature”processRequest() — returns any
Available in: controller, model, mapper, migrator, migration, tabledefinition
Category: Miscellaneous Functions
Description
Section titled “Description”Creates a controller and calls an action on it.
Which controller and action that’s called is determined by the params passed in.
Returns the result of the request either as a string or in a struct with body, emails, files, flash, redirect, status, and type.
Primarily used for testing purposes.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
params | struct | yes | — | The params struct to use in the request (make sure that at least controller and action are set). |
method | string | no | get | The HTTP method to use in the request (get, post etc). |
returnAs | string | no | — | Pass in struct to return all information about the request instead of just the final output (body). |
rollback | string | no | false | Pass in true to roll back all database transactions made during the request. |
includeFilters | string | no | true | Set to before to only execute “before” filters, after to only execute “after” filters or false to skip all filters. |
csrf | string | no | ignore | CSRF handling for this request. Default ignore preserves the historic test helper. Pass exception or abort to enforce; this is opt-in and does not change the production protectsFromForgery() default. |
Examples
Section titled “Examples”// 1. Basic usage: simulate a GET request to the Users#index action and return the rendered body.
result = processRequest(params={controller="users", action="index"});
// result -> "<html>...</html>"
// 2. Simulate a POST request to create a new user and return the full response struct.
result = processRequest(
params={controller="users", action="create", firstName="Jane", lastName="Doe"},
method="post",
returnAs="struct"
);
// result.status -> 302
// result.redirect -> "/users"
// result.body -> ""
// result.flash -> {success="User created."}
// 3. Roll back all database changes made during the request (useful in tests to keep data clean).
result = processRequest(
params={controller="users", action="create", firstName="Jane"},
method="post",
rollback=true,
returnAs="struct"
);
// result.status -> 302
// 4. Run the action without any filters (bypass before/after filter logic).
result = processRequest(
params={controller="users", action="index"},
includeFilters=false
);
// result -> "<html>...</html>"