Hello,
I'm trying to match routes on-fly by looking in the database, and so far I did this on Kohana using the following:
Route::set('category', '(<link_rewrite>(/p<page>)(/<filters>))', array(
'page' => '\d+',
'filters' => '.*',
))
->filter(function($route, $params, $request)
{
if (empty($params['link_rewrite']))
return false;
$result = DB::select('c.id_category')
->from(array('category', 'c'))
->join(array('category_lang', 'cl'), 'inner')->on('c.id_category', '=', 'cl.id_category')
->where('cl.id_lang', '=', 1)
->where('cl.link_rewrite', 'like', $params['link_rewrite'])
->limit(1)
->execute();
if ($result->count() > 0)
{
$params['controller'] = 'Category';
$params['action'] = 'index';
$params['id_category'] = $result->get('id_category');
return $params;
}
return false;
});
I have tried to use beforeMatch but so far I'm guessing that the return must be boolean. Also I tried to match all to a single controller-action and from then to use dispatcher->forward() but $router->getControllerName() and $router->getActionName() doesn't get overwritten.
There is any way to look to the database for a slug and depending on what it found, to return a controller, action and params?