Hi! I did automatic registration modules:
$modules = array();
foreach(array_diff(scandir(APP_DIR), array('..', '.')) as $dir)
{
if(is_dir(APP_DIR.'/'.$dir))
{
$modules[$dir] = array(
'className' => 'Cms\Module\\'.ucfirst($dir),
'path' => '../modules/'.$dir.'/Module.php'
);
}
}
$application->registerModules($modules);
Is there a better solution?
What is the difference these two methods?
1.
$application->registerModules(
array(
'frontend' => array(
'className' => 'Multiple\Frontend\Module',
'path' => '../apps/frontend/Module.php',
),
'backend' => array(
'className' => 'Multiple\Backend\Module',
'path' => '../apps/backend/Module.php',
)
)
);
2.
$application->registerModules(
array(
'frontend' => function($di) use ($view) {
$di->setShared('view', function() use ($view) {
$view->setViewsDir('../apps/frontend/views/');
return $view;
});
},
'backend' => function($di) use ($view) {
$di->setShared('view', function() use ($view) {
$view->setViewsDir('../apps/backend/views/');
return $view;
});
}
)
);