Zend Framework 2 - Layout and variable

前端 未结 6 864
醉梦人生
醉梦人生 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:06

    There are three ways to achieve this in ZF2 (in your controller):

    First:

    $this->layout()->someVariableName = 'Some value for the variable';
    

    Second:

    $this->layout()->setVariable('someVariableName', 'Some value for the variable');
    

    Third:

    $this->layout()->setVariables(array(
        'someVariableName' => 'Some value for the variable',
        'anotherVariable'  => 'Some value for another variable',
    );
    

提交回复
热议问题