Documentation · Chapter 09

Assemble a useful View application.

This workshop creates a small task board that remains readable PHP and reacts without a server request for every click.

Every lesson starts from the problem, explains the mechanism, then gives a concrete verification.

Build the state

Declare title and tasks as state. Keep task creation local first; persistence can be added later with an explicit API.

phpaml — zsh
#[State] private string $draft = '';
#[State] private array $tasks = [];

TextField()->value($this->state('draft'));
Button('Add')->onClick(function (): void {
    if (trim($this->draft) !== '') {
        $this->tasks[] = ['title' => $this->draft];
        $this->draft = '';
    }
});

Compose the body

Render the title, bound field, add button, and task list. Use semantic headings and labels rather than anonymous containers everywhere.

Verify the behavior

Run aml test, use keyboard-only navigation, enter several tasks, and confirm state changes without a page reload or repeated HTTP request.

SUMMARY

What to remember

  • View describes interfaces with typed PHP objects.
  • Engine runs supported frontend behavior locally.
  • State properties remain natural to read and modify.
  • Components, layouts, routes, and styles keep large interfaces organized.