title: Apigility: Send Error code 404 module.php in bootstrap
body: <p>I use APIGILITY to create a Web-service, I’d like to resolve a problem. I don’t have a specific database linked to my app ,the database  is specified by a parameter in the URL.
  For example <a href="http://sk.localhost/users-service/1" rel="nofollow">http://sk.localhost/users-service/1</a>, where 1 is the database’s paramaters “projet” you can see below.</p>
  
  <p>It’s my database .conf:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>return array(
      'db' =&gt; array(
       '1' =&gt; array(
     'driver' =&gt; 'Pdo',
           'dsn' =&gt; 'mysql:dbname=projet;host=localhost',
           'driver_option' =&gt; array(
              1002 =&gt; 'SET NAMES \'UTF8\''
              ), 
           
           ),
          
          '2' =&gt; array(
           'driver' =&gt; 'Pdo',
           'dsn' =&gt; 'mysql:dbname=cgm;host=localhost',
           'driver_option' =&gt; array(
              1002 =&gt; 'SET NAMES \'UTF8\''
              ),
           ));</code></pre>
  </div>
  </div>
  </p>
  
  <p>And it’s my code to specify the database with the parameter:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>class Module
  {
     private $id_base;
     private $conf_Users_tables;
     private $conf_Droits_tables; 
     private $data;
  
    
      public function init(ModuleManager $moduleManager)
      {  
          $events = $moduleManager-&gt;getEventManager();
          $events-&gt;attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'initDBSConfig'));
      }
  
      public function onBootstrap(MvcEvent $e)
      {
          $eventManager        = $e-&gt;getApplication()-&gt;getEventManager();
          $moduleRouteListener = new ModuleRouteListener();
          $moduleRouteListener-&gt;attach($eventManager);
          $eventManager-&gt;attach('route', array($this, 'checkRoute'));
      }
  
      public function getConfig()
      {
          return include __DIR__ . '/config/module.config.php';
      }
  
      public function getAutoloaderConfig()
      {
          return array(
              'Zend\Loader\StandardAutoloader' =&gt; array(
                  'namespaces' =&gt; array(
                      __NAMESPACE__ =&gt; __DIR__ . '/src/' . __NAMESPACE__,
                  ),
              ),
          );
      }
  
      public function checkRoute(MvcEvent $e) 
      {      
          $route = $e-&gt;getRouteMatch()-&gt;getParams();
          $this-&gt;id_base = $route['id_base'];
  
      }
  
      
  
       
  
  public function initDBSConfig(ModuleEvent $e)
      { 
          $conf = include __DIR__ . '/../../config/Dbs.conf.php';
          $this -&gt;data = $conf['db'];
          $this-&gt;initConfTables(); 
      }
  
      function initConfTables()
      {   
          $confUsers = include __DIR__ . '/../../config/Users.conf.php';
          $confDroits = include __DIR__ . '/../../config/Droits.conf.php';
          $this-&gt;conf_Users_tables = $confUsers;
          $this-&gt;conf_Droits_tables = $confDroits;
      }
  
      public function getServiceConfig()
       {
          return array(
               'factories' =&gt; array(  
                   'Application\Model\UsersTable' =&gt;  function($sm) {     
                      if(isset($this-&gt;data[$this-&gt;id_base]))
                      {                                    
                          $tableGateway = $sm-&gt;get('UsersTableGateway');
                          $table = new UsersTable($tableGateway);
                          return $table;
                      }
                      else
                      {
                          return;
                      }
                   },
                   'UsersTableGateway' =&gt; function ($sm) {
                           
                       $dbAdapter = $sm-&gt;get('SwitchDbAdapter');
                      
                       $resultSetPrototype = new ResultSet();                    
                       $resultSetPrototype-&gt;setArrayObjectPrototype($sm-&gt;get('UsersModel'));
                       return new TableGateway($this -&gt;data['t'.$this-&gt;id_base]['users'], $dbAdapter, null, $resultSetPrototype);
                   },
                   'UsersModel' =&gt; function($sm) {
                       $usersModel = new UsersModel();
                       $usersModel-&gt;setConfig($this-&gt;conf_Users_tables[$this-&gt;id_base]);
                       return $usersModel;
                   },
  
          
                   'Application\Model\DroitsTable' =&gt;  function($sm) {                    
                       $tableGateway = $sm-&gt;get('DroitsTableGateway');
                       $table = new DroitsTable($tableGateway);
                       return $table;
                   },
                   'DroitsTableGateway' =&gt; function ($sm) {                     
                      $dbAdapter = $sm-&gt;get('SwitchDbAdapter');
                      
                          $resultSetPrototype = new ResultSet();
                          $resultSetPrototype-&gt;setArrayObjectPrototype($sm-&gt;get('DroitsModel'));
                          return new TableGateway($this -&gt;data['t'.$this-&gt;id_base]['droits'], $dbAdapter, null, $resultSetPrototype);
                      
                   },
                   'DroitsModel' =&gt; function($sm) {
                       $droitsModel = new DroitsModel();
                       $droitsModel-&gt;setConfig($this-&gt;$conf_Droits_tables[$this-&gt;id_base]);
                       return $droitsModel;
                   },
                   
                   'SwitchDbAdapter' =&gt; function ($sm) {
                     
                          $dbAdapter = new \Zend\Db\Adapter\Adapter($this-&gt;data[$this-&gt;id_base]);
                          return $dbAdapter;
                      
                   },
                  ),          
              );
       }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>So I’d like the application send HTTP ERROR code 404 if the parameter in the URL  doesn’t match to any databases in my config. </p>