Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZF2: Zend Framework 2 - how to render output without layout

I know that I can use this

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

   return $result;
}

But how do I pass variables to view? Before I did this

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

But now I have only one option either return array and then layout is there or return $result then variables are not in the view.

like image 445
Sergey Romanov Avatar asked Jun 11 '12 03:06

Sergey Romanov


2 Answers

In your example you could write like this:

public function providerAction()
{
    $result = new ViewModel();
    $result->setTerminal(true);
    $result->setVariables(array('items' => 'items'));
    return $result;
}
like image 59
AlloVince Avatar answered Nov 22 '22 23:11

AlloVince


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

$result = new ViewModel(array('items' => $items));
like image 44
Patito Avatar answered Nov 22 '22 23:11

Patito