ZF2: Zend Framework 2 - how to draw output without a layout

I know I can use this

public function providerAction() { $result = new ViewModel(); $result->setTerminal(true); return $result; } 

But how to pass variables for viewing? Before i did it

 return array('items' => $items); 

But now I have only one option, either an returned array, and then a layout or $result return, then the variables are not displayed in the view.

+6
source share
2 answers

In your example, you can write like this:

 public function providerAction() { $result = new ViewModel(); $result->setTerminal(true); $result->setVariables(array('items' => 'items')); return $result; } 
+23
source

The previous answer works just fine. I just want to add that instead of using setVariables you can also pass your variables directly when instantiating the ViewModel as follows:

 $result = new ViewModel(array('items' => $items)); 
+2
source

Source: https://habr.com/ru/post/917750/


All Articles