Как я могу создать собственный mvc динамический c маршрут, подобный /$name/$id/
?
Мои маршруты:
//$router->match('GET|POST', '/', 'FrontController@Index'); //this works front page
//$router->match('GET|POST', '/(\[a-z0-9\-]+)/(\d+)', 'FrontController@renderProject'); //tried also this but didn't work
$router->mount('/', function() use ($router, $tpl) {
$router->match('GET|POST', '/', 'FrontController@Index'); //if I use here front page doesn't work..
$router->get('/(\[a-z0-9\-]+)/(\d+)', 'FrontController@renderProject'); //this should be that dynamic route what I want to get work.
});
Мой рендерProje c функция:
public function renderProject($name, $id)
{
$tpl = App::View(BASEPATH . 'view/');
$tpl->dir = "front/";
$tpl->title = Lang::$word->META_T36;
$row = Db::run()->pdoQuery('SELECT c.name AS name, p.id AS id, p.title AS title, p.body AS body, p.cover AS cover FROM projects AS p INNER JOIN categories AS c ON p.category = c.id WHERE p.id ="' . $id . '" AND c.name = "' . $name . '";')->results()) {
$tpl->data = $row;
$tpl->template = 'front/project.tpl.php';
}
Как правильно поступить?