title: ZF3: Controllers with child routes doesn't work
body: <p>I'm ZF2 developer and I'm migrating to ZF3 and I'm having troubles whith some controllers.</p>
  
  <p>For example, I have this url: <a href="http://localhost/admin" rel="nofollow noreferrer">http://localhost/admin</a> which calls to the correct controller (IndexController) and show the correct view. But If I want to associate this url: <a href="http://localhos/admin/articulo" rel="nofollow noreferrer">http://localhos/admin/articulo</a> with ArticuloController doesn't work. When I call to this url: <a href="http://localhost/admin/articulo" rel="nofollow noreferrer">http://localhost/admin/articulo</a> the controller called is AdminController and doesn't find the view.</p>
  
  <p><strong>OPTION 1 => module.config.php:</strong></p>
  
  <pre><code>namespace Admin;
  
  use Zend\Router\Http\Literal;
  use Zend\Router\Http\Segment;
  use Zend\ServiceManager\Factory\InvokableFactory;
  
  return [
      'router' =&gt; [
          'routes' =&gt; [
              'admin' =&gt; [
                  'type'    =&gt; Segment::class,
                  'options' =&gt; [
                      'route'    =&gt; '/admin[/:action]',
                      'defaults' =&gt; [
                          'controller' =&gt; Controller\IndexController::class,
                          'action'     =&gt; 'index',
                      ],
                  ],
              ],
              'admin/articulos' =&gt; [
                  'type'    =&gt; Segment::class,
                  'options' =&gt; [
                      'route'    =&gt; '/admin/articulos[/:action]',
                      'defaults' =&gt; [
                          'controller' =&gt; Controller\ArticulosController::class,
                          'action'     =&gt; 'index',
                      ],
                  ],
              ],            
          ],
      ],
      'controllers' =&gt; [
          'factories' =&gt; [
              Controller\IndexController::class =&gt; InvokableFactory::class,
              Controller\ArticulosController::class =&gt; InvokableFactory::class,
          ],
      ],
      'view_manager' =&gt; [
          'display_not_found_reason' =&gt; true,
          'display_exceptions'       =&gt; true,
          'doctype'                  =&gt; 'HTML5',
          'not_found_template'       =&gt; 'error/404',
          'exception_template'       =&gt; 'error/index',
          'template_map' =&gt; [
              'layout/layout'           =&gt; __DIR__ . '/../view/layout/layout-admin.phtml',
              'admin/index/index'       =&gt; __DIR__ . '/../view/admin/index/index.phtml',
              'error/404'               =&gt; __DIR__ . '/../view/error/404.phtml',
              'error/index'             =&gt; __DIR__ . '/../view/error/index.phtml',
          ],
          'template_path_stack' =&gt; [
              __DIR__ . '/../view',
          ],
          /*
           * Con este array de parámetros permitimos enviar datos y no mostrar vista
           */
          'strategies' =&gt; [
              'ViewJsonStrategy',
          ],           
      ],
  ];
  </code></pre>
  
  <p><strong>OPTION 2 => module.config.php (ZF2 style):</strong></p>
  
  <pre><code>namespace Admin;
  
  use Zend\Router\Http\Literal;
  use Zend\Router\Http\Segment;
  use Zend\ServiceManager\Factory\InvokableFactory;
  
  return [
      'router' =&gt; [
          'routes' =&gt; [
              'admin' =&gt; [
                  'type'    =&gt; Segment::class,
                  'options' =&gt; [
                      'route'    =&gt; '/admin[/:action]',
                      'defaults' =&gt; [
                          'controller' =&gt; Controller\IndexController::class,
                          'action'     =&gt; 'index',
                      ],
                  ],
              ],
              'admin/articulos' =&gt; [
                  'type'    =&gt; Literal::class,
                  'options' =&gt; [
                      'route'    =&gt; '/admin/articulos[/:action]',
                      'defaults' =&gt; [
                          'controller' =&gt; 'Articulos',
                          'action'     =&gt; 'index',
                      ],                 
                  ],
                  'may_terminate' =&gt;  true,
                  'child_routes'  =&gt;  [
                      'default'   =&gt;[
                          'type'  =&gt;  Segment::class,
                          'options'   =&gt;  [
                              'route' =&gt;  '/[:controller[/:action][/:id1]]',
                              'constraints'   =&gt;  [
                                  'controller'    =&gt;  '[a-zA-Z][a-zA-Z0-9_-]*',
                                  'action'        =&gt;  '[a-zA-Z][a-zA-Z0-9_-]*',
                                  'id1'           =&gt;  '[0-9_-]*'
                              ],
                              'defaults'  =&gt;  [],
                          ],
                      ],
                  ],
              ],            
          ],
      ],
      'controllers' =&gt; [
          'factories' =&gt; [
              Controller\IndexController::class =&gt; InvokableFactory::class,
              Controller\ArticulosController::class =&gt; InvokableFactory::class,
          ],
      ],
      'view_manager' =&gt; [
          'display_not_found_reason' =&gt; true,
          'display_exceptions'       =&gt; true,
          'doctype'                  =&gt; 'HTML5',
          'not_found_template'       =&gt; 'error/404',
          'exception_template'       =&gt; 'error/index',
          'template_map' =&gt; [
              'layout/layout'           =&gt; __DIR__ . '/../view/layout/layout-admin.phtml',
              'admin/index/index'       =&gt; __DIR__ . '/../view/admin/index/index.phtml',
              'error/404'               =&gt; __DIR__ . '/../view/error/404.phtml',
              'error/index'             =&gt; __DIR__ . '/../view/error/index.phtml',
          ],
          'template_path_stack' =&gt; [
              __DIR__ . '/../view',
          ],
          /*
           * Con este array de parámetros permitimos enviar datos y no mostrar vista
           */
          'strategies' =&gt; [
              'ViewJsonStrategy',
          ],           
      ],
  ];
  </code></pre>
  
  <p><strong>OPTION 3 => module.config.php (following zf3 tutorial):</strong>
  <a href="https://docs.zendframework.com/zend-mvc/routing/#http-routing-examples" rel="nofollow noreferrer">https://docs.zendframework.com/zend-mvc/routing/#http-routing-examples</a></p>
  
  <pre><code>namespace Admin;
  
  use Zend\Router\Http\Literal;
  use Zend\Router\Http\Segment;
  use Zend\ServiceManager\Factory\InvokableFactory;
  
  return [
      'router' =&gt; [
          'routes' =&gt; [
              'admin' =&gt; [
                  'type'    =&gt; Segment::class,
                  'options' =&gt; [
                      'route'    =&gt; '/admin[/:action]',
                      'defaults' =&gt; [
                          'controller' =&gt; Controller\IndexController::class,
                          'action'     =&gt; 'index',
                      ],
                  ],
                  'may_terminate' =&gt;  true,
                  'child_routes'  =&gt;  [
                      'articulos' =&gt;  [
                          'type'  =&gt;  Segment::class,
                          'options'   =&gt;  [
                              'route' =&gt;  '/articulos[/:action]',
                              'defaults'  =&gt;  [
                                  'controller'    =&gt; Controller\ArticulosController::class,
                                  'action'        =&gt;  'index'
                              ],
                          ],
                      ],
                  ],
              ],           
          ],
      ],
      'controllers' =&gt; [
          'factories' =&gt; [
              Controller\IndexController::class =&gt; InvokableFactory::class,
              Controller\ArticulosController::class =&gt; InvokableFactory::class,
          ],
      ],
      'view_manager' =&gt; [
          'display_not_found_reason' =&gt; true,
          'display_exceptions'       =&gt; true,
          'doctype'                  =&gt; 'HTML5',
          'not_found_template'       =&gt; 'error/404',
          'exception_template'       =&gt; 'error/index',
          'template_map' =&gt; [
              'layout/layout'           =&gt; __DIR__ . '/../view/layout/layout-admin.phtml',
              'admin/index/index'       =&gt; __DIR__ . '/../view/admin/index/index.phtml',
              'error/404'               =&gt; __DIR__ . '/../view/error/404.phtml',
              'error/index'             =&gt; __DIR__ . '/../view/error/index.phtml',
          ],
          'template_path_stack' =&gt; [
              __DIR__ . '/../view',
          ],
          /*
           * Con este array de parámetros permitimos enviar datos y no mostrar vista
           */
          'strategies' =&gt; [
              'ViewJsonStrategy',
          ],           
      ],
  ];
  </code></pre>
  
  <p>For all of the configurations when I call the url: <a href="http://localhost/admin/articulos" rel="nofollow noreferrer">http://localhost/admin/articulos</a> the view that I get is ... </p>
  
  <p><a href="https://i.stack.imgur.com/sbZaN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sbZaN.png" alt="enter image description here"></a></p>
  
  <p>Where you can see that the controller called is Admin\Controller\IndexController and not Admin\Controller\ArticulosController</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Update 1:</p>
  
  <p>The option 3 configuration works fine!!! I have delete all the content from /cache directory and now the controller is found but ... I have got now an error rendering the template ...</p>
  
  <p><strong>Message:</strong></p>
  
  <blockquote>
    <p>Zend\View\Renderer\PhpRenderer::render: Unable to render template
    "admin/articulos/index"; resolver could not resolve to a file</p>
  </blockquote>
  
  <p><strong>Stack Trace:</strong></p>
  
  <blockquote>
    <p>0 /var/www/html/31juegos/vendor/zendframework/zend-view/src/View.php(207):
    Zend\View\Renderer\PhpRenderer->render()</p>
    
    <p>1 /var/www/html/31juegos/vendor/zendframework/zend-view/src/View.php(236):
    Zend\View\View->render(Object(Zend\View\Model\ViewModel))</p>
    
    <p>2 /var/www/html/31juegos/vendor/zendframework/zend-view/src/View.php(200):
    Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))</p>
    
    <p>3 /var/www/html/31juegos/vendor/zendframework/zend-mvc/src/View/Http/DefaultRenderingStrategy.php(105):</p>
    
    <p>Zend\View\View->render(Object(Zend\View\Model\ViewModel))</p>
    
    <p>4 /var/www/html/31juegos/vendor/zendframework/zend-eventmanager/src/EventManager.php(322):
    Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))</p>
    
    <p>5 /var/www/html/31juegos/vendor/zendframework/zend-eventmanager/src/EventManager.php(171):
    Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent))</p>
    
    <p>6 /var/www/html/31juegos/vendor/zendframework/zend-mvc/src/Application.php(367):
    Zend\EventManager\EventManager->triggerEvent(Object(Zend\Mvc\MvcEvent))</p>
    
    <p>7 /var/www/html/31juegos/vendor/zendframework/zend-mvc/src/Application.php(348):
    Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))</p>
    
    <p>8 /var/www/html/31juegos/public/index.php(40): Zend\Mvc\Application->run()</p>
    
    <p>9 {main}</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/8tky5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8tky5.png" alt="enter image description here"></a></p>