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

Router annotations with multi modules project

Good evening,

Description of my case:

I have multi modules project and need to use Annotations routing rather than default routing. The problem (as I see) that I have to register controllers of each module globally to make routing with annotations work. This behavior opposite the encapsulation principle, as you have to define each controller in a global autoloader.

I read many threads about same issue, but the replies comes with that modules are loaded after routes executed. Is there any way to load modules before routing ? Or is there any way to tell routes to go to the correct module instead of throwing an exception that "Project\Modules\Example\Controllers\IndexController" does not exist ?

hello juan fixate in this phalcon bootstrap that believes a few days ago. I think this is you need.

Good luck

Thanks for replying, but this bootstrap is for traditional routing, not the annotations one.

Isn't exactly you need but you can modify router service to read modules and add they're controllers and router annotations

I will give a try and inform you.

Thanks for replying :)

hello juan fixate in this phalcon bootstrap that believes a few days ago. I think this is you need.

Good luck

This exactly what I am talking about! Why we need to register all controllers in the global autoloader rather than encapsulating them per module ?

https://forum.phalcon.io/discussion/67/how-to-work-with-annotations-router-in-multi-module-applications#C308