I'm trying to map pages from database to root of domain:
now I have have
/posts/post1-url
/posts/post2-url/slashed
I want
/post1-url
/post2-url/slashed
How can I make router that matches the strings above with db, and if not matched, continues matching routeList like below?
<?php
public static function createRouter(): RouteList
{
$router = new RouteList;
$router->addRoute('/', 'Home:default');
$router->addRoute('/auth', 'Auth:default');
$router->addRoute('/auth/<action>', 'Auth:<action>');
$router->addRoute('/admin', 'Admin:default');
$router->addRoute('/admin[/<action>][/<slug>]', 'Admin:<action>');
$router->addRoute('/<slug>', 'Home:viewPage');
$router->addRoute('<presenter>/<action>', '<presenter>:<action>');
return $router;
}
I have presenter action that can process showing the database post, but found no way to match route list in action, or other way to combine the match+routeList
I am using this approach.
BlogRouter.php
RouterFactory.php
You can simply update BlogRouter code to use database. But you should cache uris, not query them on each request.