Complex actions
In the previous example, the pathComponents is left to false because we wanted the action to respond to requests to the root / page. To map actions that respond to more complex routes like /about/contact, we use pathComponents to pass an array of RequestPathComponent objects representing the segments of the path.
In this example, we map an action that will respond when the /about/contact path is requested:
1
...
2
3
$e->Actions->mapAction([
4
"aboutContact",
5
new \Cherrycake\Actions\ActionsActionHtml([
6
"moduleType" => ACTION_MODULE_TYPE_APP,
7
"moduleName" => "About",
8
"methodName" => "viewContact",
9
"request" => new \Cherrycake\Actions\Request([
10
"pathComponents" => [
11
new \Cherrycake\Actions\RequestPathComponent([
12
"type" => REQUEST_PATH_COMPONENT_TYPE_FIXED,
13
"string" => "about"
14
]),
15
new \Cherrycake\Actions\RequestPathComponent([
16
"type" => REQUEST_PATH_COMPONENT_TYPE_FIXED,
17
"string" => "contact"
18
])
19
]
20
])
21
])
22
]);
23
24
...
Copied!
See RequestPathComponent::__construct to learn more about other options when setting up path components for complex routes.
Copy link