Action Models

Concept

Action Models are invokable classes that process incoming requests and offer an abstraction of the Model to the View.

How does it work?

  1. The Action Model's __invoke() method is executed. It receieves as first argument a PSR-7 request instance, following by the route params.
  2. __invoke() is responsible to update the Model (add/update/delete entities, send an email, validate form, ...) and sets the information (application state) that the View will need.
  3. The View fetches its own data from the Action Model.

Example

In this minimal example, route parameter name is being made accessible to the view template.

<?php
class HelloActionModel
{
    public 
$name;

    public function 
__invoke($request$name)
    {
        
$this->name $name;
    }
}

Dependency injection

Action Models' dependencies are automatically injected through the constructor by the Container.