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

Router mount

File configs/services.php

Why only works if i include the file, all others DI accept class call.

Thanks!

$di->set('router', function () {

    $router = new Router();
    include __DIR__.'/../library/System/Routes/Admin.php';
    include __DIR__.'/../library/System/Routes/Frontend.php';
    $router->mount(new \System\Routes\Frontend);
    $router->mount(new \System\Routes\Admin);

    $router->notFound(array(
        "controller" => "index",
        "action" => "notfound"
    ));

    return $router;
});

You have to configure the loader to autoload those classes.

edited Jul '15

But they are configured, all other $di->set the class's works

Example $di dispatcher My class \System\Layout, Acl, Assets works fine

all others di set also, only router that does not load

$di->set('dispatcher', function() use ($di)
{
    $dispatcher = new Dispatcher();
    $dispatcher->setDefaultNamespace("Apps\\Frontend\\Controllers");

    $eventsManager = new EventsManager();
    $eventsManager->enablePriorities(true);

    #$eventsManager->attach('dispatch',  new Acl);
    $eventsManager->attach('dispatch',  new  Layout());
    $eventsManager->attach('dispatch', new Assets());

    $dispatcher->setEventsManager($eventsManager);

    return $dispatcher;
});

Maybe router are be calling before autoloader, just a look into, because i'm not a zephyr programmer so I can be wrong but thanks for always help!

https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/application.zep

Linha 210

let router = <RouterInterface> dependencyInjector->getShared("router");

Linha 280

moduleObject->registerAutoloaders(dependencyInjector);

Then register an autoloader outside of registerAutoloaders() in the module to load your routes.

Fine, so I register before the Module.php and not in module.php anymore? thanks andres