take a look my example below
$di->set(
$service,
function () use ($config) {
$router = new Router(false);
$router->removeExtraSlashes(true);
$router->setDefaultModule("customer");
$router->setDefaultNamespace("LicMan\\Modules\\Customer\\Controllers\\");
$router->add( "/:controller/([a-zA-Z\-]+)/:params", [
"controller" => 1,
"action" => 2,
"params" => 3
])->convert("action", function ($action) {
return Text::camelize($action);
});
$router->add("/:controller/([a-zA-Z\-]+)", [
"controller" => 1,
"action" => 2
])->convert("action", function ($action) {
return Text::camelize($action);
});
$router->add("/:controller", [
"controller" => 1,
"action" => "index"
]);
$admin = new Router\Group([
"module" => "admin",
"controller" => "index",
"namespace" => "LicMan\\Modules\\Admin\\Controllers\\"
]);
$admin->setPrefix("/admin");
$admin->add( "/:controller/:action/:params", [
"controller" => 1,
"action" => 2,
"params" => 3
])->convert("action", function ($action) {
return Text::camelize($action);
});
$admin->add("/:controller/:action", [
"controller" => 1,
"action" => 2
])->convert("action", function ($action) {
return Text::camelize($action);
});
$admin->add("/:controller", ["controller" => 1,
"action" => "index"
]);
$admin->add("", array("controller" => "index", "action" => "index"));
$router->mount($admin);
return $router;
}
);