Reputation: 689
I know the multi module application structure of Phalcon, but is it possible to have a nested module structure like following example shows? I want to have a system, where I can hot-plug new sub-modules (for backend, frontend) to the system. Routes, menu entries etc. should get automatically extended when I copy a new module folder into the sub-module folder.
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
Is there a way with events to hot-plug such modules to the system?
Upvotes: 2
Views: 3962
Reputation: 41
You can approach my organization structure of modules in the application: https://github.com/oleksandr-torosh/yona-cms
The modules are presented as separate entities: https://github.com/oleksandr-torosh/yona-cms/tree/master/app/modules
Likely for your application you do not need to use the standard multi-modular structure from the box
Upvotes: 1
Reputation: 26403
yes you can. the first solution what i can think of is this:
while registering your loader in 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();
notice registerPrefixes. you can register different prefix for different models like:
$loader->registerPrefixes(
array(
"FModel_" => $config->application->forumModels,
"NModel_" => $config->application->newsModels,
)
);
you can register prefixes to other things too. I also added this example
$loader->registerNamespaces(array(
'RemoteApi' => $config->application->librariesDir . 'RemoteApi/'
));
this way you can order your stuff under different namespace's.
Upvotes: 7