2012-09-11 5 views
1

에 젠드 프레임 워크 2에 관한 질문이 있습니다. 내 응용 프로그램에는 제 전체 응용 프로그램을 처리하는 모듈이 있습니다.젠드 프레임 워크 2 테마 관리자

더 나은 개선을 위해 테마 매니저를 개발하고 싶습니다.

Theme Manager는? theme = lightTheme와 같은 url 매개 변수로 작동해야합니다. 테마는 모듈 외부의 폴더 "템플릿"으로 구성됩니다. 테마에는보기 스크립트도 포함되어야합니다.

필자는 일부 ZF2 문서를 읽는 것으로부터 일부 수신기 이벤트를 통해이를 달성 할 수 있습니다.

누구나 괜찮습니까? 아니면이 요구 사항을 해결할 수있는 방법을 보여줄 수 있습니까? 나는이 패턴 일 수 있다고 생각

+0

나는이뿐만 아니라에 대한 리스너 이벤트를 들었어요의 경로 이벤트를 사용하도록 변경. 그 의미는 Module.php 클래스에서 응용 프로그램에 이벤트를 등록한다는 것입니다. 그런 다음 일부 조건에 따라 레이아웃 파일을 변경합니다. 물론 각 레이아웃 파일은 diff CSS 파일을 사용하는 '테마'입니다. 내가 본 웹 페이지에 대한 링크를 올려 놓으려고합니다. –

답변

5

...

테마 폴더 구조

/path/to/themes 
/path/to/themes/some_theme 
/path/to/themes/some_theme/layout.phtml 
/path/to/themes/another_theme 
/path/to/themes/another_theme/layout.phtml 

설정/module.config.php

return array(
    'view_manager' => array(
     'template_path_stack' => array(
      '/path/to/themes', 
     ), 
    ), 
); 

Module.php

namespace Something; 

class Module 
{ 
    public function onBootstrap(\Zend\EventManager\EventInterface $e) 
    { 
     $application = $e->getApplication(); 
     $em = $application->getEventManager(); 
     $em->attach('route', function($e) { 

      // decide which theme to use by get parameter 
      // $layout = 'some_theme/layout'; 
      // $layout = 'another_theme/layout'; 
      $e->getViewModel()->setTemplate($layout); 
     }); 
    } 
} 

// 편집 : 대신 controllerLoader