How many routerFactorys are possible

Bill Lions
Member | 47
+
0
-

In my RouterFactory I have:

declare(strict_types=1);

namespace App\Router;

use Nette;
use Nette\Application\Routers\RouteList;


final class RouterFactory
{
        use Nette\StaticClass;

        public static function createRouter(): RouteList
        {
                $router = new RouteList;
                $router->addRoute('/', 'Default:default');
                $router->addRoute('[<module>[/<presenter>[/<action>[/<id>]]]]', 'Default:Default:default');
                return $router;
        }
}

In another directory for my ServicesModule I have.

declare(strict_types=1);

namespace App\Router;

use Nette;
use Nette\Application\Routers\RouteList;


final class servicesRouterFactory
{
        use Nette\StaticClass;

        public static function createRouter(): RouteList
        {
                $router = new RouteList;
                $router->addRoute('/services', 'Services:Services:default');
                $router->addRoute('/services/consulting', 'Services:Default:consulting');
                $router->addRoute('/services/outsourcing', 'Services:Default:outsourcing');
                $router->addRoute('/services/teams', 'Services:Default:teams');
                return $router;
        }
}

Then in my PorfolioModule I have:

declare(strict_types=1);

namespace App\Router;

use Nette;
use Nette\Application\Routers\RouteList;


final class portfolioRouterFactory
{
        use Nette\StaticClass;

        public static function createRouter(): RouteList
        {
                $router = new RouteList;
                $router->addRoute('/portfolio', 'Portfolio:Portfolio:default');
                return $router;
        }
}

Accessing the root directory, or any of the services routes is not an issue.
However, the portfolio router seems never to be ‘picked up’, resulting in an error:

Nette\Application\BadRequestException #404
No route for HTTP request

Each of the routers is called from config file, and the router files are ‘seen’, but when I look in Tracy, the routes are listed as:

/services presenter = Services:Services
action = default

/services/consulting presenter = Services:Default
action = consulting

/services/outsourcing presenter = Services:Default
action = outsourcing

/services/teams presenter = Services:Default
action = teams

/ presenter = Default:Default
action = default

Why is the portfolio router not being added to the routes?

chemix
Nette Core | 1310
+
0
-

@BillLions and how look like your confiuguration file ? config.neon with router registration ?

Bill Lions
Member | 47
+
0
-

chemix wrote:

@BillLions and how look like your confiuguration file ? config.neon with router registration ?

Ahh, good call.
The default router is not called, and is commented out in the config

services:
# router: App\RouterFactory::createRouter

the sericesRouterFactory is called from the ServicesModule/config/common.neon file:

parameters:
user:
defaultStatus: 2

services:
router: App\Router\servicesRouterFactory::createRouter

the portfolio router is call from PortfolioModule/config/common.neon file:

>

services:
router: App\Router\portfolioRouterFactory::createRouter

nightfish
Member | 518
+
0
-

Bill Lions wrote:
the portfolio router is call from PortfolioModule/config/common.neon file:

services:
router: App\Router\portfolioRouterFactory::createRouter

How is the file PortfolioModule/config/common.neon loaded? Is it included into the main app/config/config.neon or loaded by an extension?

Last edited by nightfish (2020-07-17 10:08)

Bill Lions
Member | 47
+
0
-

nightfish wrote:

Bill Lions wrote:
the portfolio router is call from PortfolioModule/config/common.neon file:

services:
router: App\Router\portfolioRouterFactory::createRouter

How is the file PortfolioModule/config/common.neon loaded? Is it included into the main app/config/config.neon or loaded by an extension?

The PortfolioModule/config/common.neon is loaded from the Bootstrap.php using Finder, which locates all common.neon files, and loads them.

foreach (Finder::findFiles('common.neon')->from(__DIR__) as $file) {
    $path = $file->getRealPath(); // $file is an instance of SplFileInfo
    $configurator->addConfig( $path );
}