Skip to content

Commit 312fda8

Browse files
github-actions[bot]wheels-docs-validator[bot]
andauthored
docs(api): validate Controller section (run 25476931516) (wheels-dev#2462)
Co-authored-by: wheels-docs-validator[bot] <wheels-docs-validator@users.noreply.github.com>
1 parent 60330ef commit 312fda8

51 files changed

Lines changed: 1697 additions & 181 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tools/docs-validation/state.json

Lines changed: 914 additions & 0 deletions
Large diffs are not rendered by default.

vendor/wheels/controller/miscellaneous.cfc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ component {
163163
* @disposition Set to `inline` to have the browser handle the opening of the file (possibly inline in the browser) or set to `attachment` to force a download dialog box.
164164
* @directory Directory outside of the web root where the file exists. Must be a full path.
165165
* @deleteFile Pass in `true` to delete the file on the server after sending it.
166+
* @deliver When set to `false`, the file will not be sent to the browser (used for testing).
166167
*/
167168
public any function sendFile(
168169
required string file,

vendor/wheels/controller/redirection.cfc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ component {
1919
* @host Set this to override the current host.
2020
* @protocol Set this to override the current protocol.
2121
* @port Set this to override the current port number.
22+
* @method HTTP method constraint used when matching routes.
2223
* @url Redirect to an external URL.
2324
* @delay Set to `true` to delay the redirection until after the rest of your action code has executed.
24-
* @encode [see:URLFor].
25+
* @encode Encode URL parameters using `EncodeForURL()`. Please note that this does not make the string safe for placement in HTML attributes, for that you need to wrap the result in `EncodeForHtmlAttribute()` or use `linkTo()`, `startFormTag()` etc instead.
2526
*/
2627
public void function redirectTo(
2728
boolean back = false,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// 1. Embed the CSRF token in a manually-built form hidden field
2+
token = authenticityToken();
3+
writeOutput('<input type="hidden" name="authenticityToken" value="' & token & '">');
4+
5+
// 2. Pass the token as a request header for an AJAX call (e.g. in a JavaScript data island)
6+
writeOutput('<meta name="csrf-token" content="' & authenticityToken() & '">');
7+
// JavaScript can then read this and send it as the X-CSRF-Token header with each POST request.
8+
9+
// 3. Include the token in a JSON API response body so a client can replay it
10+
tokenValue = authenticityToken();
11+
writeOutput(serializeJSON({authenticityToken = tokenValue}));
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// Cache the `termsOfUse` action.
1+
// 1. Cache the `termsOfUse` action for the default 60 minutes.
22
caches("termsOfUse");
33

4-
// Cache the `termsOfUse` action for 30 minutes.
5-
caches(actions="browseByUser, browseByTitle", time=30);
4+
// 2. Cache two actions for 30 minutes.
5+
caches(actions="browseByUser,browseByTitle", time=30);
66

7-
// Cache the `termsOfUse` and `codeOfConduct` actions, including their filters.
8-
caches(actions="termsOfUse, codeOfConduct", static=true);
7+
// 3. Cache the `termsOfUse` and `codeOfConduct` actions, including their filters.
8+
caches(actions="termsOfUse,codeOfConduct", static=true);
99

10-
// Cache content separately based on region.
11-
caches(action="home", key="request.region");
10+
// 4. Cache content separately based on region.
11+
caches(action="home", appendToKey="request.region");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// 1. Clear all cached action metadata for the current controller.
2+
clearCachableActions();
3+
4+
// 2. Clear the cached metadata for a single action.
5+
clearCachableActions(action="termsOfUse");
6+
7+
// 3. Clear the cached metadata for a list of specific actions.
8+
clearCachableActions(action="browseByUser,browseByTitle");
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
// Get filter chain.
1+
// 1. Get the entire filter chain for the current controller
22
myFilterChain = filterChain();
3+
// myFilterChain -> array of structs, each with keys: through, type, only, except, arguments
4+
// e.g. [{ through: "checkLogin", type: "before", only: "", except: "" }, ...]
35

4-
// Get filter chain for after filters only.
5-
myFilterChain = filterChain(type="after");
6+
// 2. Get only the before-filters
7+
beforeFilters = filterChain(type="before");
8+
for (f in beforeFilters) {
9+
writeOutput(f.through);
10+
}
11+
12+
// 3. Get only the after-filters
13+
afterFilters = filterChain(type="after");
14+
writeOutput(arrayLen(afterFilters));
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1-
// Always execute `restrictAccess` before all actions in this controller.
1+
// 1. Run `restrictAccess` before every action in this controller (declared inside config()).
22
filters("restrictAccess");
33

4-
// Always execute `isLoggedIn` and `checkIPAddress` (in that order) before all actions in this controller, except the `home` and `login` actions.
4+
// 2. Run two before-filters on every action except `home` and `login`.
55
filters(through="isLoggedIn, checkIPAddress", except="home, login");
6+
7+
// 3. Run `auditLog` after only the `create`, `update`, and `delete` actions.
8+
filters(through="auditLog", type="after", only="create, update, delete");
9+
10+
// 4. Prepend a filter so it runs before any already-registered filters.
11+
filters(through="maintenanceCheck", placement="prepend");
12+
13+
// Note: filter functions must be declared as `private` in the controller
14+
// to prevent them from being routed as public actions.
15+
// Example controller setup:
16+
// component extends="Controller" {
17+
// function config() {
18+
// filters("restrictAccess");
19+
// }
20+
// private function restrictAccess() {
21+
// if (!isLoggedIn()) {
22+
// redirectTo(route="login");
23+
// }
24+
// }
25+
// }
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
// Get the current value of notice in the Flash
1+
// 1. Get the current value of a specific key in the Flash
22
notice = flash("notice");
3+
// notice -> "Your profile was updated successfully."
34

4-
// Get the entire Flash as a struct
5-
flashContents = flash();
5+
// 2. Get the entire Flash as a struct when no key is passed
6+
flashContents = flash();
7+
// flashContents -> {notice: "Record saved.", error: "Something went wrong."}
8+
9+
// 3. Check for a key before reading it to avoid an empty-string fallback
10+
if (flashKeyExists("error")) {
11+
errorMessage = flash("error");
12+
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
flashClear();
1+
// 1. Clear all flash data
2+
flashClear();
3+
4+
// 2. Insert some messages, then clear them all before redirecting
5+
flashInsert(notice="Record saved.");
6+
flashInsert(warning="Check your settings.");
7+
// Oops — wipe everything and start fresh
8+
flashClear();
9+
// flash() is now an empty struct: {}
10+
11+
// 3. Clear flash conditionally inside a controller action
12+
function checkout() {
13+
if (!isLoggedIn()) {
14+
flashClear();
15+
flashInsert(error="You must be logged in to check out.");
16+
redirectTo(action="login");
17+
}
18+
}

0 commit comments

Comments
 (0)