Reputation: 78981
Can we have multiple modules inside another module?
May be a similar structure like this:
/module
/Application
/module
/SubApplication1
/SubApplication2
I am looking for an simple example or a article someone know about this. I have googled for reference but seems like this portion of zf2 is not explored so far.
Upvotes: 1
Views: 612
Reputation: 5539
It is easy to have multiple namespaces within your module. The only thing you need to do is to provide configuration to the Zend Autoloader(s). For the Zend\Loader\StandardAutoloader
the config can be set in the module and would look something like this:
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
// This is the default namespace most probably the module dir name
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
// And this is for your custom namespace within the module
'SomeNamespace' => __DIR__ . '/src/' . 'SomeNamespace',
'OtherNamespace' => __DIR__ . '/src/' . 'OtherNamespace',
),
),
);
}
For the Zend\Loader\ClassMapAutoloader
it is the same concept. You just need to match the namespaces to the class files:
// file: ~/autoload_classmap.php
return array(
'SomeNamespace\Controller\SomeController' => __DIR__ . '/src/SomeNamespace/Controller/SomeController.php',
'OtherNamespace\Controller\OtherController' => __DIR__ . '/src/OtherNamespace/Controller/OtherController.php',
);
Something to be caution about! Make sure that your submodule namespace's name doesn't collide with other modules namespaces.
Hope this helps :)
Stoyan
Upvotes: 1