Configure Literal and Segment routes in module.config.php with child routes and constraints.
Routing in Laminas
// module/Blog/config/module.config.php
use LaminasRouterHttpSegment;
use LaminasRouterHttpLiteral;
return [
"router" => [
"routes" => [
"blog" => [
"type" => Literal::class,
"options" => [
"route" => "/blog",
"defaults" => ["controller" => ControllerPostController::class, "action" => "index"],
],
"may_terminate" => true,
"child_routes" => [
"post" => [
"type" => Segment::class,
"options" => [
"route" => "/[:action[/:id]]",
"constraints" => ["action" => "[a-zA-Z][a-zA-Z0-9_-]*", "id" => "[0-9]+"],
"defaults" => ["action" => "index"],
],
],
],
],
],
],
];
// Generate URL in view
echo $this->url("blog/post", ["action" => "view", "id" => 42]);