Zend Framework 2 - Layout and variable

前端 未结 6 803
醉梦人生
醉梦人生 2021-01-31 04:50

i have a layout used by all my views and i need to assign a variable from a controller to this layout , if i use this method on a controller it doesn\'t work :

p         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 05:05

    Rob Allen has posted a great article about how to access view variables in another view model (e.g.: layout)

    Basically the following code, placed inside your layout.phtml, will match your needs:

    viewModel()->getCurrent()->getChildren();
    $child = $children[0];
    ?>
    
    escape($child->myvar);?>
    

提交回复
热议问题