2014-02-05 62 views
2

我知道Phalcon的多模块应用程序结构,但有可能像下面的例子一样具有嵌套的模块结构吗?我想有一个系统,在那里我可以将新的子模块(用于后端,前端)热插入系统。当我将一个新的模块文件夹复制到子模块文件夹中时,路径,菜单条目等应该自动扩展。使用Phalcon PHP框架嵌套的多模块应用程序?

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 

有没有办法用事件来热插拔这样的模块到系统?

+0

使用标准多模块化结构,我认为最起码你要做的就是与逻辑来定制你的路由器。我认为针对多模块应用程序的建议方法是将所有模块放在顶层(例如后端和前端)。 –

回答

7

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

在注册您的装载机在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/' 
)); 

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

相关问题