title: creating a zf2 module without controllers with some autoloaded classes
body: <p>I'm trying to create a Zend Framework 2 module that has some generic classes that I want to use in some of my controllers.</p>
  <p>I created a directory called 'tux-drink-zf2-module' in 'vendor' directory.</p>
  <p>I added that directory to 'application.config.php'.</p>
  <p>my Module.php has the following:</p>
  <pre><code>&lt;?php
  
  namespace TuxDrink;
  
  use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
  
  class Module implements AutoloaderProviderInterface
  {
  public function getAutoloaderConfig()
  {
      return array(
          'Zend\Loader\ClassMapAutoloader' =&gt; array(
              __DIR__ . '/autoload_classmap.php',
          ),
          'Zend\Loader\StandardAutoloader' =&gt; array(
              'namespaces' =&gt; array(
                  __NAMESPACE__ =&gt; __DIR__ . '/src/' . __NAMESPACE__,
              ),
          ),
      );
  }
  }
  </code></pre>
  <h1>update</h1>
  <p>new:</p>
  <p>my autoload_classmap.php has the following:</p>
  <pre><code>&lt;?php
  // Generated by ZF2's ./bin/classmap_generator.php
  return array(
  'TuxDrink\Module'                                  =&gt; __DIR__ . '/Module.php',
  'TuxDbCassandra'                                   =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Cassandra/TuxDbCassandra.php',
  'TuxDrink\Drink\Model\AlcoholSum'                  =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/AlcoholSum.php',
  'TuxDrink\Drink\Model\AlcoholSumTable'             =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/AlcoholSumTable.php',
  'TuxDrink\Drink\Model\Drink'                       =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/Drink.php',
  'TuxDrink\Drink\Model\DrinkBrand'                  =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkBrand.php',
  'TuxDrink\Drink\Model\DrinkBrandTable'             =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkBrandTable.php',
  'TuxDrink\Drink\Model\DrinkCompany'                =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkCompany.php',
  'TuxDrink\Drink\Model\DrinkCompanyTable'           =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkCompanyTable.php',
  'TuxDrink\Drink\Model\DrinkFlavor'                 =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkFlavor.php',
  'TuxDrink\Drink\Model\DrinkFlavorTable'            =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkFlavorTable.php',
  'TuxDrink\Drink\Model\DrinkFlavorType'             =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkFlavorType.php',
  'TuxDrink\Drink\Model\DrinkFlavorTypeTable'        =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkFlavorTypeTable.php',
  'TuxDrink\Drink\Model\DrinkIngredient'             =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkIngredient.php',
  'TuxDrink\Drink\Model\DrinkIngredientTable'        =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkIngredientTable.php',
  'TuxDrink\Drink\Model\DrinkIngredientType'         =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkIngredientType.php',
  'TuxDrink\Drink\Model\DrinkIngredientTypeTable'    =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkIngredientTypeTable.php',
  'TuxDrink\Drink\Model\DrinkTable'                  =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkTable.php',
  'TuxDrink\Drink\Model\DrinkType'                   =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkType.php',
  'TuxDrink\Drink\Model\DrinkTypeTable'              =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkTypeTable.php',
  'TuxDrink\Drink\Model\GlobalImage'                 =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImage.php',
  'TuxDrink\Drink\Model\GlobalImageLink'             =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageLink.php',
  'TuxDrink\Drink\Model\GlobalImageLinkPending'      =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageLinkPending.php',
  'TuxDrink\Drink\Model\GlobalImageLinkPendingTable' =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageLinkPendingTable.php',
  'TuxDrink\Drink\Model\GlobalImageLinkTable'        =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageLinkTable.php',
  'TuxDrink\Drink\Model\GlobalImageTable'            =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageTable.php',
  'TuxDrink\Drink\Model\GlobalImageType'             =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageType.php',
  'TuxDrink\Drink\Model\GlobalImageTypeTable'        =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageTypeTable.php',
  'TuxDrink\Drink\Model\LiquidColor'                 =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/LiquidColor.php',
  'TuxDrink\Drink\Model\LiquidColorTable'            =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/LiquidColorTable.php',
  'TuxDrink\Drink\Model\LiquidColorType'             =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/LiquidColorType.php',
  'TuxDrink\Drink\Model\LiquidColorTypeTable'        =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/LiquidColorTypeTable.php',
  'TuxDrink\Drink\Model\PendingDrinkCommits'         =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/PendingDrinkCommits.php',
  'TuxDrink\Drink\Model\PendingDrinkCommitsTable'    =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/PendingDrinkCommitsTable.php',
  'TuxDrink\TuxDb\Mysql\Drink\TuxDbMysqlDrink'       =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/TuxDbMysqlDrink.php',
  'TuxDrink\TuxDb\Drink\Util\AlcoholCalc'            =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Util/AlcoholCalc.php',
  'TuxDrink\TuxDb\Mysql\TuxDbMysql'                  =&gt; __DIR__ . '/src/TuxDrink/TuxDb/Mysql/TuxDbMysql.php',
  'TuxDrink\TuxDb\TuxDbAbstract'                     =&gt; __DIR__ . '/src/TuxDrink/TuxDb/TuxDbAbstract.php',
  'TuxDrink\TuxDb\TuxDbInterface'                    =&gt; __DIR__ . '/src/TuxDrink/TuxDb/TuxDbInterface.php',
  'TuxDrink\TuxDb\TuxDrinkInterface'                 =&gt; __DIR__ . '/src/TuxDrink/TuxDb/TuxDrinkInterface.php',
  'TuxDrink\TuxDb\TuxTableInterface'                 =&gt; __DIR__ . '/src/TuxDrink/TuxDb/TuxTableInterface.php',
  );
  </code></pre>
  <p>but still when I try to refresh my project I get the following error:</p>
  <pre><code> Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (tux-drink-zf2-module) could not be initialized.' in /Volumes/2g-storage/projects/php-projects/myalcoholist/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 144
  </code></pre>
  <p>maybe i'm missing some other files in order to properly configure this as a Module?
  remember, this is a package for sources, without controllers, views and actions.</p>
  <p>any information regarding the issue would be greatly appreciated.</p>
  <h1>update</h1>
  <p>this issue was solved when i fixed the directories structure.</p>
  <p>but when I'm trying to use the module in one the the controllers.</p>
  <p>in my case i need to use two classes from the TuxDrink module.</p>
  <p>class 'TuxDbMysqlDrink' and class 'TuxDbMysql'.</p>
  <p>I need to use them in controller 'DrinkController' in action 'drink-brand-autocomplete'.</p>
  <p>I use the following code:</p>
  <pre><code>use \TuxDb\Mysql\Drink\TuxDbMysqlDrink;
  
  use \TuxDb\Mysql\TuxDbMysql;
  
  
  public function drinkBrandAutocompleteAction() {
      $param=$this-&gt;getRequest()-&gt;getQuery('q');
      if ($param) {
          $drink = new TuxDbMysqlDrink();
          $result=$drink-&gt;autoCompleteDrinkBrand($param);
          return $result;
      }
  }
  </code></pre>
  <p>and I get the following error message:</p>
  <pre><code> Fatal error: DrinkManagement\Controller\DrinkController cannot use TuxDrink\TuxDb\Mysql\Drink\TuxDbMysqlDrink - it is not a trait in /Volumes/2g-storage/projects/php-projects/myalcoholist/module/DrinkManagement/src/DrinkManagement/Controller/DrinkController.php on line 197
  </code></pre>
  <p>any ideas?</p>
  <p>tried to google, couldn't understand what it means &quot;it is not a trait&quot;</p>
  <h1>update</h1>
  <p>resolved it with this code:</p>
  <pre><code>public function drinkBrandAutocompleteAction() {
      $param=$this-&gt;getRequest()-&gt;getQuery('q');
      if ($param) {
          $drink = new \TuxDrink\TuxDb\Mysql\Drink\TuxDbMysqlDrink();
          $result=$drink-&gt;autoCompleteDrinkBrand($param);
          die(var_export($result,1));
       ...
  </code></pre>