I am using league/route 4.2. I am trying to implement a lazy loading controller using wildcard.
class Router
{
private $container;
private $router;
function __construct()
{
$this->container = new Container();
$this->router = new \League\Route\Router();
$this->mapRouters();
$this->dispatch();
}
private function mapRouters() {
$this->router->map('GET', '/', [MainController::class, 'index']);
//$this->router->map('GET', 'Main', 'Nanitelink\Module\Main\MainController::index');
$this->router->map('GET', '{module}', 'Nanitelink\Module\{module}\{module}Controller::index');
}
private function dispatch() {
$request = $this->container->get('Zend\Diactoros\ServerRequest');
$response = $this->router->dispatch($request);
$emitter = $this->container->get('Zend\HttpHandlerRunner\Emitter\SapiEmitter');
$emitter->emit($response);
}
}
Now I know for a fact that the commented route works. I tried to replace it with wildcard, but probably I am not getting the syntax correctly, but it throws following exception.
Class 'Nanitelink\Module\{module}\{module}Controller' not found
What is the right way to use wildcard routing in league/route? Documentation does not explain how to use wildcard in lazy loading way.