Passing or Forwarding Route


I want to pre-check the current uri on routing to check exists pages. If doesnt exist the page, pass the matched route.

For examle uri: /hello-world

// Uri matched first
// I want to check `hello-world` on Pages db
// If the page found, run this route
// If doesnt exist, pass this route
$router->add('/{alias:[0-9a-z\-]+}', array(
    'controller' => 'pages',
    'action' => 'index',
    'alias' => 1

// If above doesnt matched, run this route
$router->add('/hello-world', array(
    'controller' => 'hello',
    'action' => 'world'

I hope I can tell. How can i do this?


You can catch exception with dispatcher then redirect as required.
Use Phalcon\Events\Manager with dispatcher and beforeException event with a plugin class.
Example :

edited 20d ago

Use beforeMatch method? To check if route with this alias exists perhaps?