We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Where do Routes Go?

I am wondering where do you place the routes?

On this page I see usage of the routes, but I can't figure out how they tie into $app->handle() somehow. https://docs.phalcon.io/en/latest/reference/routing.html#defining-routes



2.3k
Accepted
answer

From what I know,

$di->set('router', function ()
    $router = new \Phalcon\Mvc\Router();

    $router->add('/', array(
        'controller' => 'index',
        'action' => 'index',
    ));

    return $router;
));

$app = new \Phalcon\Mvc\Application();
$app->setDI($di); /** This is where the app handles the router service. */
echo $app->handle()->getContent();

As for where to place the routes, it doesn't matter. As long as you inject the service using php $app->setDI($di) or php $app = new \Phalcon\Mvc\Application($di) after you set the router service.

I'm new to Phalcon.. So, I'm still studying.

Hey thanks! I thought thats where it went but I wasn't sure. I guess its just like the Views. They should put that in the docs for people of lesser intelligence like myself:)