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

The group of routes does not contain any routes

I'm trying to define a group of routes but Phalcon raises an exception when I mount the group.

class UpdatesGroup extends Phalcon\Mvc\Router\Group {

  public function initialize() {
    // Sets the default controller for the following routes.
    $this->setPaths(['controller' => 'updates']);

    $this->addGet('/', ['action' => 'recents']);
    $this->addGet('/?tab=popolari', ['action' => 'populars']);
    $this->addGet('/?tab=recenti', ['action' => 'recents']);
    $this->addGet('/?tab=in-base-ai-miei-tag', ['action' => 'basedOnMyTags']);
    $this->addGet('/?tab=piu-votati', ['action' => 'mostVoted']);
    $this->addGet('/?tab=piu-discussi', ['action' => 'mostDiscussed']);
    $this->addGet('/rss', ['action' => 'rss']);
  }
}

$router = new Phalcon\Mvc\Router(false);

$router->mount(new UpdatesGroup());

The exception message is: "The group of routes does not contain any routes" .

What is wrong?



98.9k

Are you using 1.1.0?

Note that Phalcon\Mvc\Router only works with URIs but not with query strings so /?tab=popolari and /?tab=recenti are both threaded as just /

Yes I'm using 1.1.0.

Thank you for the update about the Router. It seems to me that the initialize() method is never called. Shouldn't be called automatically from the constructor?



98.9k

I see the problem it's only calling "initialize" if an array is passed to the constructor :/

$router->mount(new UpdatesGroup([]));


24.4k
Accepted
answer

Yes, using an empty array fixed the issue. It's a bug anyway.

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &paths) == FAILURE) {
  RETURN_MM_NULL();
}