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

Disable default routing functionallity

Im using Phalcon 3.2.1

In the docs it says if you new up Router like so

$router = new Router(false);

It will disable the default routing stuff. I have done this and it is still trying to do the default routing.

My code

# region Router Init
use Phalcon\Mvc\Router\Group;
use Phalcon\Mvc\Router;

/**
 * @var $router Phalcon\Mvc\Router()
 */
$router = new Router(false);
$router->setDI($di);

# endregion

$router->add('/', 'Index::index');

$router->addGet('/home', 'Index::index');

When going to /home i get the error 'HomeController handler class cannot be loaded'



8.2k
Accepted
answer

Solved the problem, Phalcon automaticly builds a router in the DI container, for anyone else who may have this problem you need to override the default router with the new one in services.php

$di->set('router', function () use ($di) {
    return include APP_PATH . "/config/router.php";
});


9.7k

For anyone struggling with the defaults, there is the option of setting up DI with no defaults then adding only what you need. There is also the micro option, a good choice for Web services that do not need DI.

Micro option have DI of course, it doesn't have dispatcher.



9.7k

I looked back at my "micro" code. I removed micro and use a small selection of Phalcon services without DI or routing. The flexibility of Phalcon is amasing compared to the framework I tried to use last year. Advertised as light weight because the initial download is small, the first file uses composer to flood my tiny terabyte disk with code. At execution time, every class loads every other class through dependencies.

The micro option was way smaller to start with and an excellent option for Web services.

But it has di as well as routing, it's just woring behind the bars, it doesn't have dispatcher. You can for example set which di should micro use.