User Interface
Business Model

One major benefit of Server Side Rendered applications is ability to directly interact with data. In other applications you may need to manually process data but in Agile Toolkit we use data mapping framework.

/* Showing Class definition.
class DemoInvoice extends Model
    public ?string $titleField = 'reference';

    protected function init(): void

        $this->addField('date', ['type' => 'date']);

$model = new DemoInvoice(new Persistence\Array_($_SESSION['atk4_ui_intro_demo'] ?? []));
$model->onHook(Model::HOOK_AFTER_SAVE, function (Model $model) {
    $_SESSION['atk4_ui_intro_demo'][$model->getId()] = (clone $model->getModel())->addCondition($model->idField, $model->getId())->export(null, null, false)[$model->getId()];

Header::addTo($owner, ['Set invoice data:']);
$form = Form::addTo($owner);

$entity = $model->tryLoad(1);
if ($entity === null) {
    // set default data
    $entity = $model->createEntity();
        'id' => 1,
        'reference' => 'Inv-' . random_int(1000, 9999),
        'date' => new \DateTime(),

$form->onSubmit(function (Form $form) {

    return new JsToast('Saved!');

View::addTo($owner, ['ui' => 'divider']);
Set invoice data:

This code shows you a combination of 3 objects:

  • Form - a generic view that can display and handle any form
  • Model - defines fields for a business object
  • Persistence - creates a persistent storage location for the data

All three are combined by "setModel()" function and that is consistent throughout all the views.