Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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. http://docs.phalconphp.com/en/latest/reference/routing.html#defining-routes



1.5k
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:)