switon/view

HTML views with request-scoped state, controller template resolution, and an HTTP response bridge for Switon Framework

Maintainers

Package info

github.com/switon-php/view

Documentation

pkg:composer/switon/view

Statistics

Installs: 2

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-06-07 05:28:43 UTC


README

CI PHP 8.3+

Switon's view layer for router-mapped HTML actions, request-local state, widgets, and layout/block rendering.

Highlights

  • View routing: #[ViewMapping] and related attributes route page actions into the HTML view flow.
  • Flexible template resolution: ViewInterface::render() accepts direct template paths and Controller::Action targets.
  • Shared layout shell: setLayout(), @section, and @yield let page templates reuse one wrapper.
  • Request-local view state: ViewContext keeps layout, variables, and rendered content together.
  • Widget support: reusable page parts can be built with widget contracts.
  • HTTP bridge: ViewRenderer turns action return values into rendered HTML responses.

Installation

composer require switon/view

Quick Start

use Switon\Routing\Attribute\RequestMapping;
use Switon\Routing\Attribute\ViewMapping;
use Switon\Viewing\ViewInterface;
use Switon\Core\Attribute\Autowired;

#[RequestMapping('/user')]
class UserController
{
    #[Autowired] protected ViewInterface $view;

    #[ViewMapping('profile')]
    public function profileAction(): array
    {
        return [
            'title' => 'Profile',
            'user' => ['name' => 'Mark'],
        ];
    }
}

Docs: https://docs.switon.dev/latest/view

License

MIT.