2012-08-29 4 views

답변

25

이 사용보기에서 변수에 액세스 할 수 있습니다

echo $this->partial('layout/header', array('vr' => 'zf2')); 

에 의해 달성 될 수있다

echo $this->vr; 

이 module.config.php 파일의 당신의 view_manager에 다음 줄을 추가하는 것을 잊지 마세요.

'layout/header'   => __DIR__ . '/../view/layout/header.phtml', 

추가 한 후 이미 허용 대답에 명시된이

return array( 

'view_manager' => array(
     'template_path_stack' => array(
      'user' => __DIR__ . '/../view' , 
     ), 
     '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', 

      'layout/header'   => __DIR__ . '/../view/layout/header.phtml',    

      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
      'error/index'    => __DIR__ . '/../view/error/index.phtml', 
     ), 


    ),  

); 
+1

모두보기 변수를 전달하려면 – davmor

+0

'$ this-> viewModel()은 부분적으로 : '$ this-> viewModel() -> getCurrent() -> getVariables() -> getCurrent() -> getVariables()는 [ArrayObject]를 반환합니다 (http://php.net/manual/en/class.arrayobject.php). – davmor

+0

추가 데이터를 병합하려면 array_merge가 작동합니다. echo $ this-> partial ('mypartial', array_merge ($ this-> viewModel() -> getCurrent() -> getVariables(), [moredata])); – Killan

5

으로, 당신은

echo $this->partial('layout/header', array('vr' => 'zf2')); 

을 사용할 수있는 것 같습니다 그러나 당신은 당신의 module.config에 layout/header을 정의해야 .php. 당신이 당신의 template_map을 복잡하게하지 않으려면


, 당신은 직접 부분을 가리 키도록 template_path_stack을 기준으로 상대 경로를 사용할 수 있습니다. 당신의 module.config.php에서

'view_manager' => array(
     /* [...] */ 
     'template_path_stack' => array(
      'user' => __DIR__ . '/../view' , 
     ), 
     'template_map' => array(
      'layout/layout'   => __DIR__ . '/../view/layout/layout.phtml', 

      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
      'error/index'    => __DIR__ . '/../view/error/index.phtml', 
     ), 
    ),  
); 

하고 listsnippet.phtml 그런 다음 다음과 같은 코드를 사용할 수 있습니다, .../view/mycontroller/snippets/listsnippet.phtml에있다 :

사용자가 정의한 가정

echo $this->partial('mycontroller/snippets/listsnippet.phtml', array('key' => 'value'));