Skip to content

Register routes

mezzio/config/routes/hello.php
<?php

declare(strict_types=1);

use App\Handler\HelloHandler;
use Mezzio\Application;

return static function (Application $app): void {
    $app->get('/hello', HelloHandler::class, 'hello');
};
mvc/module/Application/config/hello.config.php
<?php

declare(strict_types=1);

namespace Application;

use Laminas\Router\Http\Literal;
use Laminas\ServiceManager\Factory\InvokableFactory;

return [
    'router'      => [
        'routes' => [
            'hello' => [
                'type'    => Literal::class,
                'options' => [
                    'route'    => '/hello',
                    'defaults' => ['controller' => Controller\HelloController::class, 'action' => 'greet'],
                ],
            ],
        ],
    ],
    'controllers' => [
        'factories' => [
            Controller\HelloController::class => InvokableFactory::class,
        ],
    ],
];

A form route must accept both GET and POST. In Mezzio, use $app->route() and list both. An MVC Literal route accepts every method.