Actions guide
Actions is the routing core module of Cherrycake, and allows your application to receive requests and attend them accordingly.
When using Actions, all the modules who will be receiving requests should map their actions in the Module::mapActions method, by calling Actions::mapAction.
Actions is the default base core module because it is what you'll need in most cases. If you're experimenting with different ways of using Cherrycake, you can specify a different set of base modules in Engine::init
When a request is received, Actions will look through all the mapped actions. If any of them matches the current request, it will load the associated module and run the mapped method.
Actions calls mapActions methods on all available modules during its initialization, using the Engine::callMethodOnAllModules
For example, the following module maps a simple action named home that will call the viewHome method when the root page / is requested:
1
<?php
2
3
namespace CherrycakeApp\Home;
4
5
class Home extends \Cherrycake\Module {
6
7
public static function mapActions() {
8
global $e;
9
10
$e->Actions->mapAction([
11
"home",
12
new \Cherrycake\Actions\ActionHtml([
13
"moduleType" => ACTION_MODULE_TYPE_APP,
14
"moduleName" => "Home",
15
"methodName" => "viewHome",
16
"request" => new \Cherrycake\Actions\Request([
17
"pathComponents" => false
18
])
19
])
20
]);
21
22
}
23
24
function viewHome() {
25
// Show the home page
26
}
27
28
}
Copied!
Copy link