Error "The requested URL could not be matched by routing" using ZF2

0

I'm using apigility (ZF2). The following error occurs when sending a request: The requested URL could not be matched by routing. The error occurs when I try to get a get request through the link: http://0.0.0.0:8888/leads using the postman (chrome plugin).

The error is supposed to refer to some route error. However, you can not see this error yet.

The directory structure follows below:

The code for my chat / module.php file is as follows:

<?php
   namespace chat;

   use chat\V1\Rest\Leads\LeadsEntity;
   use chat\V1\Rest\Leads\LeadsMapper;
   use Zend\Db\ResultSet\ResultSet;
   use Zend\Db\TableGateway\TableGateway;

   use ZF\Apigility\Provider\ApigilityProviderInterface;

 class Module implements ApigilityProviderInterface
 {
   public function getConfig()
   {



      return array(
        'factories' => array(
            'chatLeadsTableGateway' =>  function($sm) {
                $dbAdapter = $sm->get('Adaptador');
                $resultSetPrototype = new ResultSet();
                $resultSetPrototype->setArrayObjectPrototype(new LeadsEntity());
                return new TableGateway('nomedatable', $dbAdapter, null, $resultSetPrototype);
            },
            'chat\V1\Rest\Leads\LeadsMapper' => function($sm) {
                $tableGateway = $sm->get('chatLeadsTableGateway');
                return new LeadsMapper($tableGateway);
            }
        ),
     );

   }

   public function getAutoloaderConfig()
   {
    return array(
        'ZF\Apigility\Autoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ => __DIR__,
            ),
        ),
    );
  }
 }

The code for the chat / module.config.php file is as follows:

<?php
   return array(
      'router' => array(
         'routes' => array(
            'chat.rest.leads' => array(
              'type' => 'Segment',
                 'options' => array(
                    'route' => '/leads[/:leads_id]',
                       'defaults' => array(
                          'controller' =>          'chat\V1\Rest\Leads\Controller',
                ),
            ),
        ),
    ),
), 

Below the project folder structure

    
asked by anonymous 22.06.2015 / 19:56

1 answer

0

The module.php file is wrong. The getConfig method is not taking the route configuration that is defined in module.config.php. To do this change this method to:

public function getConfig()
{
    include __DIR__ . '/../../config/module.config.php';
}

The previous content of this method should actually be inside getServiceConfig (), as follows:

public function getServiceConfig()
 {
    return array(
        'factories' => array(
            'chatLeadsTableGateway' =>  function($sm) {
                $dbAdapter = $sm->get('Adaptador');
                $resultSetPrototype = new ResultSet();
                $resultSetPrototype->setArrayObjectPrototype(new LeadsEntity());
                return new TableGateway('nomedatable', $dbAdapter, null, $resultSetPrototype);
            },
            'chat\V1\Rest\Leads\LeadsMapper' => function($sm) {
                $tableGateway = $sm->get('chatLeadsTableGateway');
                return new LeadsMapper($tableGateway);
            }
        ),
    );
}

This will solve the route problem.

    
22.06.2015 / 20:26