I want to create an Utils module in zf2 wich is going to have classes that will be used for other modules, but no controllers, models or views, ZendStudio only creates modules with a predefined structure. What is the recommended structure for the module I want, keep in mind I want those classes to be autloaded. Thanks in advance
0
votes
1 Answers
0
votes
There isn't any good structure, you can use classmap file to register autoloading classmap or just copy a basic Module.php at the root of your module then place all your utility classes in module/ToolsModule/src/ToolsModule
for exemple.
The only thing to do when you have this structure to benefit from autoloader is to give namespaces that fit the structure .
Exemple :
file : module/ToolsModule/src/ToolsModule/Adapter/MyAdapter.php
namespace in that file : ToolsModule/Adapter
You can organize by pattern type, or by feature, whatever you want that fit the coding standard you have.
Basic Module.php :
<?php
namespace ToolsModule;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
class Module implements AutoloaderProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}