phalcon/cphalcon · error · Phalcon\Mvc\Router\Exceptions\EmptyGroupOfRoutes

The group of routes does not contain any routes

Error message

The group of routes does not contain any routes

What it means

Router::mount() requires a RouteGroupInterface that actually contains routes: it fires router:beforeMount, fetches group->getRoutes(), and if the collection is empty throws EmptyGroupOfRoutes. An empty group would silently register nothing, so the router treats it as a configuration mistake. A prefix, hostname, or beforeMatch alone does not count as content.

Source

Thrown at phalcon/Mvc/Router.zep:1818

     *
     * @param GroupInterface group
     *
     * @return static
     */
    public function mount(<GroupInterface> group) -> <static>
    {
        var groupRoutes, beforeMatch, hostname, route, eventsManager;

        let eventsManager = this->eventsManager;

        if typeof eventsManager == "object" {
            eventsManager->fire("router:beforeMount", this, group);
        }

        let groupRoutes = group->getRoutes();

        if unlikely empty groupRoutes {
            throw new EmptyGroupOfRoutes();
        }

        /**
         * Get the before-match condition
         */
        let beforeMatch = group->getBeforeMatch();

        if beforeMatch !== null {
            for route in groupRoutes {
                route->beforeMatch(beforeMatch);
            }
        }

        // Get the hostname restriction
        let hostname = group->getHostName();

        if hostname !== null {
            for route in groupRoutes {

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Add at least one route to the group before mounting: $group->add('/dashboard', ['controller' => 'dashboard', 'action' => 'index']); then $router->mount($group);
  2. If the group may legitimately be empty (dynamic modules), guard the mount: if (count($group->getRoutes()) > 0) { $router->mount($group); }
  3. Check that you mounted the same group instance you populated, not a fresh copy

Example fix

// before
$group = (new Group())->setPrefix('/admin');
$router->mount($group); // no routes added yet

// after
$group = (new Group())->setPrefix('/admin');
$group->add(
    '/dashboard',
    ['controller' => 'dashboard', 'action' => 'index']
);
$router->mount($group);
Defensive patterns

Strategy: validation

Validate before calling

// only mount groups that actually contain routes
$group = new \Phalcon\Mvc\Router\Group('/admin');
// ... conditional route additions ...

if (count($group->getRoutes()) > 0) {
    $router->mount($group);
} else {
    $logger->warning('Skipped mounting empty group /admin');
}

Type guard

function isMountableGroup(\Phalcon\Mvc\Router\RouteGroupInterface $group): bool
{
    return count($group->getRoutes()) > 0;
}

Try / catch

try {
    $router->mount($group);
} catch (\Phalcon\Mvc\Router\Exceptions\EmptyGroupOfRoutes $e) {
    // treat as a build error: a route group lost all its definitions
    $logger->error('Refused to mount empty group: ' . $e->getMessage());
    throw $e;
}

Prevention

When it happens

Trigger: $router->mount((new Group())->setPrefix('/admin')) where no $group->add(...) was called before mount; calling mount() before a conditional block that adds routes; a group whose routes are attached to a different instance (e.g. you built routes on a cloned/copied group).

Common situations: Refactoring route registration into group classes and forgetting the load() / add() calls; conditionally skipping route additions (feature flag off) while still mounting the shell group; mount ordered before route definitions in a bootstrap script.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/2cdf9c05a4421525. Report an issue: GitHub.