カテゴリー
router

routerでurlの一部をパラメーター化

module/Application/config/module.config.php

'router' => [
    'routes' => [
        'archives' => [
            'type' => Segment::class,
            'options' => [
                'route'    => '/news/archive[/:year]',
                'defaults' => [
                    'controller' => ArchiveController::class,
                    'action'     => 'byYear',
                    'year'       => date('Y'),
                ],
                'constraints' => [
                    'year' => '\d{4}',
                ],
            ],
        ],
    ],
],

アクション内でのパラメーターの取得方法

$year = $this->params()->fromRoute('year');

https://docs.laminas.dev/tutorials/in-depth-guide/understanding-routing/