PhalconCMS系统源码解析之多模块
多模块文件加载
在“app/core/loader.php”文件中,对“前台模块”和“后台模块”的“controllers”、“models”文件目录进行加载。这里是用的命名空间加载(registerNamespaces)方式,也可以用自动加载(registerDirs)来处理。

DI注册服务
私有服务
在“app/frontend/FrontendModule.php”和“app/Backend/BackendModule.php”文件中分别向DI注册前台和后台模块所需的"dispathcer调度器服务"、“url服务”以及“view模板服务”。这里需要注意的是,前后台的“dispatcher调度器服务”中设置的“默认调度器”是不一样的:

同理,前后台的“url服务”中设置的"URL前缀"也是不一样的。这是为了在程序中调用生成URL的方法($url->get("test/test");)时,自动根据当前模块来设置URL的前缀:

公用服务
在“app/core/services.php”文件中向DI注册多模块共用的公用服务,如路由服务、数据库连接服务、缓存服务、日志服务等等。多模块的路由服务如下:

"app/config/routes.php"中设置的路由规则如下:

注册多模块
以上步骤完成之后,后在"app/public/index.php"中注册多模块:

至此,PhalconCMS的多模块就能正常运行了。在浏览器中访问带有“/admin/”前缀的URL,"dispatcher调度服务"就能将请求URL分发到后台的控制器中("app/backend/controllers"),其他的URL请求,就默认分发到前台控制器("app/frontend/controllers")。
以上贴的都是代码片断,具体代码可以与优加程序开发团队交流。