Annotation runner and module registration with prefix

I am using the annotation runner and when I add a prefix it seems to fall back to the default routing pattern. ```php $router = new Phalcon\Mvc\Router\Annotations(); $router->addModuleResource('frontend', 'Foo\Frontend\Controllers\Index', '/foo'); $di->set('router', $router); ```

/**
 * @RoutePrefix("/bar")
 */
class IndexController extends ControllerBase
{

    /**
     * @Get("/")
     */
        public function indexAction()
        {
            echo "foo";
        }

}

http://example.com/foo/bar/ gives me php Phalcon\Mvc\Dispatcher->_throwDispatchException(FooController handler class cannot be loaded, 2)

Is there any obvious error in my code? I have tried multiple variants and it works without have the prefix in addModuleResource.



81.8k

The prefix in your app is different ( @RoutePrefix("/bar")) than the one you're using to register the resource: addModuleResource('frontend', 'Foo\Frontend\Controllers\Index', '/foo')



1.7k

ok, only if they are equal it works. But then I dont understand the point to allow the prefix in addModuleResource? If I remove the @RoutePrefix annotation, it fails. What I am looking for is to load the modules internal routing under a prefix. Can that be done the way I wanted to do it?



1.7k

is the purpose of the prefix in the addModuleResource to enclose files for the annotations runner (performance win) and not to prepend the route regex?



81.8k

The purpose of addModuleResource is to tell the router that is must load the annotations in the class just if the current URI starts by the prefix specified there, this allows to avoid reading controllers and their annotations without need.



1.7k

thanks phalcon. Also thanks for the great work. I will submit an NFR for this. Maybe it would be useful for more people.