2013-02-27 4 views
1

스켈레톤을 https://github.com/zendframework/ZendSkeletonApplication에서 다운로드했는데 정상적으로 작동합니다. 모든 것이 나에게 분명합니다.많은 모듈로 라우팅하는 방법은 무엇입니까?

하지만 다른 모듈을 추가하면 어떻게됩니까?

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

및 module.config.php에 경로를 변경 : 내가 이름을 변경, 골격에서 모듈을 복사 한 다음 application.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', 
     ), 
    ), 
); 

을하지만 지금은 볼 Api에서 골격의 위치까지도 레이아웃. 그것을하는 방법?

+0

모듈은 별도의 컨테이너가 아닙니다. 이들은 상호 관심사를 절단하고 응용 프로그램의 하위 섹션이 아닙니다. – Ocramius

답변

2

모든 module.config.php 파일이 하나로 병합되어 하나의 큰 구성 배열을 형성합니다.

정확히 어떻게되는지는 module.config.phproutes 배열에 사용하는 이름에 따라 다릅니다.

이미 제공된 동일한 이름을 다시 사용하는 경우 (예 : Application 모듈에 api이라는 경로가있는 경우) 이전 항목은 overriden이됩니다.

오른쪽 컨트롤러로 리디렉션하는 데 사용되는 경로는 액션과 매개 변수도 일치 여부에 따라 다릅니다. 정의 된 모든 경로 (모든 모듈에 대해)가 순서대로 검사됩니다. 현재 URL과 일치하는 첫 번째 URL이 실행됩니다.

api (경로 이름 + 경로 접두사)으로 모든 이름이 바뀌었기 때문에 모호하지는 않습니다. 따라서 완벽하게 작동합니다. 물론 다른 모듈에서 완전히 다른 짧은 경로를 정의하려는 경우 나중에 모듈과 일치해야하는 URL을 가져 오지 않아야합니다.

관련 문제