1

I downloaded Skeleton from https://github.com/zendframework/ZendSkeletonApplication and it work fine. Everything is clear to me.

But what happens when I add another module? I copy module from skeleton, I changed names, then added my new module to application.config.php:

return array(
    'modules' => array(
        'Application',
        'Api',
    ),
[...]

and change routes in module.config.php:

return array(
    'router' => array(
        'routes' => array(
            'api' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => 'api/',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Api\Controller',
                        'controller'    => 'Api',
                        'action'        => 'api',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/api[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
        ),
    ),
    'translator' => array(
        'locale' => 'en_US',
        'translation_file_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => 'Application\Controller\IndexController',
            'Application\Controller\Auth' => 'Application\Controller\AuthController'
        ),
    ),
    'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),
);

But now I see layout from api even locations from skeleton. How to do it?

Nips
  • 13,162
  • 23
  • 65
  • 103
  • Modules are _NOT_ separate containers. They are cross-concerns cutting and ar not sub-sections of your application. – Ocramius Feb 27 '13 at 20:09

1 Answers1

2

All your module.config.php files will be merged together to form one large configuration array.

What happens exactly, depends on the names you use in the module.config.php routes array.

If you reuse the same name that was already given (e.g. if there already was a route called api in your Application module), the old entry will be overriden.

Which route will be used for redirecting to the right controller, action and parameters also depends on the matching. All routes defined (over all modules) will be checked in order. The first one that matches your current URL will be executed.

In your case, there is does not seem to be any ambiguity, because you renamed everything to api (route name + route prefix), so it will work perfectly fine. of course you might also want to define totally different shorter routes in other modules, then you have to make sure that they do not fetch URLs that should have be matched by later modules.

Community
  • 1
  • 1
aufziehvogel
  • 7,167
  • 5
  • 34
  • 56