繁体   English   中英

使用Phalcon PHP框架的嵌套多模块应用程序?

[英]Nested Multi-Module app with Phalcon PHP framework?

我知道Phalcon的多模块应用程序结构,但是有可能有一个嵌套的模块结构,如下面的示例所示? 我想要一个系统,我可以将新的子模块(用于后端,前端)热插入系统。 将新模块文件夹复制到子模块文件夹时,路径,菜单条目等应自动扩展。

module-backend
    controllers
    models etc.
    sub-modules
        forum
            controllers
            models
            etc.
        news
            controllers
            models
            etc.
        users
            controllers
            models
            etc.
module-frontend
    controllers
    models
    sub-modules
        like backend module structure

有没有办法将这些模块热插拔到系统?

是的你可以。 我能想到的第一个解决方案是:

在index.php中注册你的加载器:

$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
    $config->application->controllersDir,
    $config->application->pluginsDir,
));
$loader->registerPrefixes(
        array(
            "Model_" => $config->application->modelsDir,
        )
);
$loader->registerNamespaces(array(
    'RemoteApi' => $config->application->librariesDir . 'RemoteApi/'
));

$loader->register();

通知registerPrefixes。 你可以为不同的模型注册不同的前缀,如:

$loader->registerPrefixes(
            array(
                "FModel_" => $config->application->forumModels,
                "NModel_" => $config->application->newsModels,
            )
);

你也可以为其他东西注册前缀。 我还添加了这个例子

$loader->registerNamespaces(array(
    'RemoteApi' => $config->application->librariesDir . 'RemoteApi/'
));

这样你可以在不同的命名空间下订购你的东西。

您可以在应用程序中处理我的组织模块结构: https//github.com/oleksandr-torosh/yona-cms

这些模块作为单独的实体呈现: https//github.com/oleksandr-torosh/yona-cms/tree/master/app/modules

  • 指数
  • 项目
  • 视频

可能对您的应用程序而言,您不需要使用框中的标准多模块结构

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM