> For the complete documentation index, see [llms.txt](https://cherrycake.tin.cat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cherrycake.tin.cat/version-1.x-beta/guide/actions-guide.md).

# Actions guide

When using [Actions](/version-1.x-beta/reference/core-modules/actions-1/actions.md), all the modules who will be receiving requests should map their actions in the [Module::mapActions](/version-1.x-beta/reference/core-classes/module/methods.md#mapactions) method, by calling [Actions::mapAction](/version-1.x-beta/reference/core-modules/actions-1/actions.md#mapaction).

> [Actions](/version-1.x-beta/reference/core-modules/actions-1/actions.md) 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](/version-1.x-beta/reference/core-classes/engine/methods.md#init)

When a request is received, [Actions](/version-1.x-beta/reference/core-modules/actions-1/actions.md) 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](/version-1.x-beta/reference/core-modules/actions-1/actions.md) calls [mapActions](/version-1.x-beta/reference/core-classes/module.md#mapactions) methods on all available modules during its initialization, using the [Engine::callMethodOnAllModules](/version-1.x-beta/reference/core-classes/engine/methods.md#callmethodonallmodules)

For example, the following module maps a simple action named `home` that will call the `viewHome` method when the root page `/` is requested:

```php
<?php

namespace CherrycakeApp\Home;

class Home extends \Cherrycake\Module {

    public static function mapActions() {
        global $e;
        
        $e->Actions->mapAction([
            "home",
            new \Cherrycake\Actions\ActionHtml([
                "moduleType" => ACTION_MODULE_TYPE_APP,
                "moduleName" => "Home",
                "methodName" => "viewHome",
                "request" => new \Cherrycake\Actions\Request([
                    "pathComponents" => false
                ])
            ])
        ]);
        
    }
    
    function viewHome() {
        // Show the home page
    }

}
```
