2012-08-29 10 views

cevap

25

Bu kullandığınız görünümde değişkeni erişebilir

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

sağlanabilir

echo $this->vr; 

module.config.php dosyanızın view_manager aşağıdaki satırı ekleyin unutmayın.

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

ekledikten sonra, önceden kabul cevap belirtilen bu

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

tüm görünüm değişkenleri geçmek için kısmi olarak: 'echo $ this-> kısmi ('layout/header', $ this-> viewModel() -> getCurrent() -> getVariables());' – davmor

+0

Not: Bu this-> viewModel() -> getCurrent() -> getVariables() 'bir [ArrayObject] döndürür (http://php.net/manual/en/class.arrayobject.php). – davmor

+0

Ek verileri birleştirmek için array_merge çalışır: echo $ this-> partial ('mypartial', array_merge ($ this-> viewModel() -> getCurrent() -> getVariables(), [moredata])); – Killan

5

olarak,

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

kullanabilirsiniz gibi görünüyor ama o zaman module.config içinde layout/header tanımlamak zorunda .php. Eğer senin template_map kalabalıklaştırmasını istemiyorsanız


, doğrudan kısmi işaret edecek template_path_stack dayalı göreli bir yol kullanabilirsiniz. senin module.config.php içinde

'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', 
     ), 
    ),  
); 

ve listsnippet.phtml sonra aşağıdaki kodu kullanabilirsiniz, .../view/mycontroller/snippets/listsnippet.phtml yatıyor:

tanımladığınız varsayalım

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