# Actions guide

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

> [Actions](https://cherrycake.tin.cat/version-0.x/reference/core-modules/actions-1/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](https://cherrycake.tin.cat/version-0.x/reference/core-classes/engine/methods#init)

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

}
```
