Controller
processRequest()
Signature
Section titled “Signature”processRequest() — returns any
Available in: controller, model, test, 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. |
Examples
Section titled “Examples”1. Simple request, returns rendered output as string
result = processRequest(params={controller="users", action="show", id=5});
// Returns: rendered HTML for the users/show action
2. Simulate a POST request
result = processRequest(
params={controller="users", action="create", name="Alice"},
method="post"
);
// Returns: rendered output of the create action
3. Get a detailed struct response instead of just body
result = processRequest(
params={controller="sessions", action="create", email="test@example.com"},
method="post",
returnAs="struct"
);
// Returns struct with keys: body, emails, files, flash, redirect, status, type
4. Automatically roll back database changes
result = processRequest(
params={controller="orders", action="create", product_id=42},
method="post",
rollback=true
);
// Data is inserted during the request but rolled back afterward
5. Skip all filters
result = processRequest(
params={controller="users", action="delete", id=10},
includeFilters=false
);
// Runs delete action without before/after filters
6. Run only "before" filters (useful for testing filter logic)
result = processRequest(
params={controller="users", action="edit", id=10},
includeFilters="before"
);