KoniKode · Software built with intention

KNOWLEDGE BASE

Documentation

DOCUMENTATION
CURRENT APPLICATIONClean Framework
DocumentationClean Framework

Clean Framework · DOCUMENTATION

Keep controllers small

Keep controllers small

Steps

Inject a use-case service and view factory. Read already-validated route parameters, invoke the use case, and return a Response. Do not send headers, echo HTML, or open a database connection in the controller.

// Inside a controller whose view factory and presentation service are injected.
public function index(Request $request): Response
{
    return Response::html($this->views->render('layouts/main.php', [
        'title' => 'Reading List',
        'content_view' => 'pages/index.php',
        'items' => $this->readingList->all(),
    ]));
}

This excerpt belongs to the complete Reading List controller, which includes imports, constructor, and missing-record handling. Add meaningful docblocks in your implementation.

Verify

Assert response status and escaping through the real router, not only direct method calls.

Editorial provenance

Source: resources/guides/controller.md. Source SHA-256: 1a25d44480daf7d506d61e9cad517d37298ab898b1c5e590cba9f3cb0c1ecf77.

Knowledge-base application source; editorial checkpoint 2026-10-20. See candidate status and adoption boundary.

EXPLORE FURTHER

Drag a divider or use Left and Right Arrow keys to resize. Hold Shift for larger steps. Enter hides or restores the sidebar; Home and End select its minimum or maximum width. Double-click resets the width.

Install KoniKode