Multi Modules + Annotations Routing


I am developing a multi modules application and following the tuts on

So far the app works just fine, but when I integrated it with Annotations Routing, it keeps showing

Class Multiple\Backend\Controllers\IndexController does not exist

Here is my change to the tutorial files:

In the bootstrap file:

//Specify routes for modules
$di->set('router', function () {

    $router = new Router\Annotations();

    $router->addModuleResource('backend', 'Multiple\Backend\Controllers\Index', '/api');

    return $router;

In the apps/backend/controllers/IndexController.php

namespace Multiple\Backend\Controllers;

* @RoutePrefix("/api")
class IndexController extends \Phalcon\Mvc\Controller
    * @Get("/test")
    public function indexAction()
        echo "stream";

Yet when I access via the URL:


It always shows:

Class Multiple\Backend\Controllers\IndexController does not exist

Is there anything I've done wrong with the Annotations?

You have to register the namespaces of the controllers in a global autloader. This is what I had did so far, but unfortuantely, modules are loaded after routing execution.

In you "loader.php" file, under "registerNamespaces", you have to register the classes namepsaces, like:

$loader->registerNamespaces([ 'Multiple\Backend\Controllers' => APP_PATH . '/modules/backend/controllers' ]);

It should work.