title: How to load a custom library in Zend Framework 2?
body: <p>I've been following this guide (<a href="http://socialsemanticweb.blogspot.com.au/2012/11/zend-framework-2-create-custom-library.html" rel="nofollow noreferrer">http://socialsemanticweb.blogspot.com.au/2012/11/zend-framework-2-create-custom-library.html</a>) but I can't get Zend to see my library (error message below).</p>
  
  <p>Any ideas what could be wrong? thanks</p>
  
  <p><strong>my folder structure</strong></p>
  
  <p><img src="https://i.stack.imgur.com/DbERZ.jpg" alt="http://imgur.com/Uhhm3uk"></p>
  
  <p><strong>my MyLibraryController.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace MyLibrary\Mvc\Controller;
  
  use Zend\Mvc\Controller\AbstractActionController;
  
  class MyLibraryController extends AbstractActionController {
      public function __construct() {
      }
  
      public function doSomething() {
          //instantiate your model here and return result
       $result = "test";
       return $result;
      }
  }
  </code></pre>
  
  <p><strong>my autoload_namespaces.php</strong> (inside vendor\composer)</p>
  
  <pre><code>&lt;?php
  
  // autoload_namespaces.php generated by Composer
  
  $vendorDir = dirname(__DIR__);
  $baseDir = dirname($vendorDir);
  
  return array(
      'Zend\\' =&gt; $vendorDir . '/zendframework/zendframework/library/',
      'ZendTest\\' =&gt; $vendorDir . '/zendframework/zendframework/tests/',
      'Symfony\\Component\\Console\\' =&gt; $vendorDir . '/symfony/console/',
      'Doctrine\\ORM' =&gt; $vendorDir . '/doctrine/orm/lib/',
      'Doctrine\\DBAL' =&gt; $vendorDir . '/doctrine/dbal/lib/',
      'Doctrine\\Common' =&gt; $vendorDir . '/doctrine/common/lib/',
      'DoctrineORMModule\\' =&gt; $vendorDir . '/doctrine/doctrine-orm-module/src/',
      'DoctrineORMModuleTest\\' =&gt; $vendorDir . '/doctrine/doctrine-orm-module/tests/',
      'DoctrineModule\\' =&gt; $vendorDir . '/doctrine/doctrine-module/src/',
      'DoctrineModuleTest\\' =&gt; $vendorDir . '/doctrine/doctrine-module/tests/',
      'MyLibrary\\' =&gt; $vendorDir . '/MyLibrary/library/',
  );
  </code></pre>
  
  <p><strong>my application.config.php</strong> (I've only added the MyLibrary entry. <strong>I've tried with and without it</strong>) </p>
  
  <pre><code>&lt;?php
  return array(
      // This should be an array of module namespaces used in the application.
      'modules' =&gt; array(
          'Application',
          'DoctrineModule',
          'DoctrineORMModule',
          'Directory',
          'Helpers',
      'MyLibrary',
  </code></pre>
  
  <p><strong>error message without adding MyLibrary module in application.config.php</strong></p>
  
  <pre><code>Fatal error: Class 'Directory\Controller\MyLibaryController' not found in D:\work\eclipse\htdocs\directory\module\Directory\src\Directory\Controller\DirectoryController.php on line 17
  </code></pre>
  
  <p><strong>error message with MyLibrary module entry in application.config.php</strong></p>
  
  <pre><code>Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (MyLibrary) could not be initialized.' in D:\work\eclipse\htdocs\directory\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php:175 Stack trace: #0 D:\work\eclipse\htdocs\directory\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php(149): Zend\ModuleManager\ModuleManager-&gt;loadModuleByName(Object(Zend\ModuleManager\ModuleEvent)) #1 D:\work\eclipse\htdocs\directory\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php(90): Zend\ModuleManager\ModuleManager-&gt;loadModule('MyLibrary') #2 [internal function]: Zend\ModuleManager\ModuleManager-&gt;onLoadModules(Object(Zend\ModuleManager\ModuleEvent)) #3 D:\work\eclipse\htdocs\directory\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent)) #4 D:\work\eclipse\htdocs\directory\vendor\zendframework\zendframework\library in D:\work\eclipse\htdocs\directory\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php on line 175
  </code></pre>